NAME

AnyEvent::KVStore::Etcd - An Etcd driver for AnyEvent::KVStore

VERSION

Version 0.1.0

SYNOPSIS

use AnyEvent::KVStore;
$config = { host => $host, port => $port };
my $store = AnyEvent::KVStore->new(module => 'etcd', config => $config);

DESCRIPTION

AnyEvent::KVStore::Etcd is a driver for AnyEvent::KVStore which uses the Etcd distributed key-value store as its backend. We use the Net::Etcd driver for this, though there are some important limitations.

The primary documentation for this module is in the AnyEvent::KVStore module but there are some important limitations discussed here.

This module can also be used directly for simplified access to an Etcd database.

AnyEvent Loops, Callbacks, and KVStore Operations

Net::Etcd uses AnyEvent::HTTP for its transport layer. It further blocks in an AnyEvent loop to wait for the response. For obvious reasons, this does not work. So, the main key/value operations cannot be done from inside an event loop. This leads to a number of possible solutions including forking and running the request in another process.

One option, though it does incur significant startup cost, is to use Coro and move the callback from a sub {} call to an unblock_sub {} call. This is probably the simplest approach and it works. In general you get sequential ordering but this is not a hard guarantee. Another approach might be to move processing into worker threads.

ATTRIBUTES/ACCESSORS

If accessing the module directly, the following accessors are available. These are not generally needed and are mostly used internally for managing the connection to the etcd server.

These are also keys for the config hash.

All attributes are optional.

host Str

This is the hostname for the etcd connection. It defaults to localhost.

port Int

Port for connection. It defaults to 2379.

ssl Bool default false

whether to use SSL or not. The default is no.

user Str

Username for authentication. Does not authenticate if not set.

password Str

Password for authentication.

cnx Net::Etcd

This is the active connection to the etcd database.

METHODS

read

Reads a value from a key and returns a JSON document payload.

exists

Checks to see if a key exists. Here this is no less costly than read.

list($pfx)

Returns a list of keys

write($key, $value)

Writes the key to the database and returns 1 if successful, 0 if not.

watch($pfx, $callback)

This sets up a "watch" where notifications of changed keys are passed to the script. This can only really be handled inside an AnyEvent loop because the changes can come from outside the program.

The callback takes the arguments of ($key, $value) of the new values.

AUTHOR

Chris Travers, <chris.travers at gmail.com>

BUGS

Please report any bugs or feature requests to bug-anyevent-kvstore-etcd at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=AnyEvent-KVStore-Etcd. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc AnyEvent::KVStore::Etcd

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

This software is Copyright (c) 2023 by Chris Travers.

This is free software, licensed under:

The (three-clause) BSD License