Author image Marvin Humphrey
and 1 contributors

NAME

KinoSearch::Store::LockFactory - Create Locks.

SYNOPSIS

    use Sys::Hostname;
    my $hostname = hostname();
    die "Can't get unique hostname" unless $hostname;

    my $invindex = MySchema->open('/path/to/invindex/on/nfs/volume');
    my $lock_factory = KinoSearch::Store::LockFactory->new(
        folder    => $invindex->get_folder,
        agent_id  => $hostname,
    );
    my $index_reader = KinoSearch::Index::IndexReader->open(
        invindex     => $invindex,
        lock_factory => $lock_factory,
    );

DESRIPTION

Normally, LockFactory is an internal class, quietly doing its work behind the scenes. On shared volumes, however, the locking mechanism fails, and manual intervention becomes necessary.

Both reading and writing applications accessing an index on a shared volume need to identify themselves with an agent_id, typically the hostname. Knowing the hostname makes it possible to tell which lockfiles belong to other machines and therefore must not be zapped when their pid can't be found.

Subclassing

LockFactory spins off Lock and SharedLock objects at the request of other KinoSearch classes. If the behavior of Lock and SharedLock do not suit your needs, you may substitute a custom subclass of LockFactory which spins off your own Lock subclasses.

CONSTRUCTOR

    my $lock_factory = KinoSearch::Store::LockFactory->new(
        folder    => $folder,    # required
        agent_id  => $hostname,  # required
    );

Create a LockFactory. Takes named parameters.

METHODS

make_lock

    my $exclusive_lock = $lock_factory->make_lock(
        lock_name => 'foo',
        timeout   => 5000,
    );

Returns an exclusive lock on a resource. Called with two hash-style parameters, lock_name and timeout, which are passed on to Lock's constructor.

make_shared_lock

    my $shared_lock = $lock_factory->make_lock(
        lock_name => 'foo',
        timeout   => 5000,
    );

Returns a shared lock on a resource. Called with two hash-style parameters, lock_name and timeout, which are passed on to SharedLock's constructor.

COPYRIGHT

Copyright 2007 Marvin Humphrey

LICENSE, DISCLAIMER, BUGS, etc.

See KinoSearch version 0.20.