… | |
… | |
894 | =back |
894 | =back |
895 | |
895 | |
896 | =head1 DISTRIBUTED DATABASE |
896 | =head1 DISTRIBUTED DATABASE |
897 | |
897 | |
898 | AnyEvent::MP comes with a simple distributed database. The database will |
898 | AnyEvent::MP comes with a simple distributed database. The database will |
899 | be mirrored asynchronously at all global nodes. Other nodes bind to one of |
899 | be mirrored asynchronously on all global nodes. Other nodes bind to one |
900 | the global nodes for their needs. |
900 | of the global nodes for their needs. Every node has a "local database" |
|
|
901 | which contains all the values that are set locally. All local databases |
|
|
902 | are merged together to form the global database, which can be queried. |
901 | |
903 | |
902 | The database consists of a two-level hash - a hash contains a hash which |
904 | The database structure is that of a two-level hash - the database hash |
903 | contains values. |
905 | contains hashes which contain values, similarly to a perl hash of hashes, |
|
|
906 | i.e.: |
|
|
907 | |
|
|
908 | $DATABASE{$family}{$subkey} = $value |
904 | |
909 | |
905 | The top level hash key is called "family", and the second-level hash key |
910 | The top level hash key is called "family", and the second-level hash key |
906 | is called "subkey" or simply "key". |
911 | is called "subkey" or simply "key". |
907 | |
912 | |
908 | The family must be alphanumeric, i.e. start with a letter and consist |
913 | The family must be alphanumeric, i.e. start with a letter and consist |
… | |
… | |
913 | with the name of the application or module using it. |
918 | with the name of the application or module using it. |
914 | |
919 | |
915 | The subkeys must be non-empty strings, with no further restrictions. |
920 | The subkeys must be non-empty strings, with no further restrictions. |
916 | |
921 | |
917 | The values should preferably be strings, but other perl scalars should |
922 | The values should preferably be strings, but other perl scalars should |
918 | work as well (such as undef, arrays and hashes). |
923 | work as well (such as C<undef>, arrays and hashes). |
919 | |
924 | |
920 | Every database entry is owned by one node - adding the same family/subkey |
925 | Every database entry is owned by one node - adding the same family/subkey |
921 | combination on multiple nodes will not cause discomfort for AnyEvent::MP, |
926 | combination on multiple nodes will not cause discomfort for AnyEvent::MP, |
922 | but the result might be nondeterministic, i.e. the key might have |
927 | but the result might be nondeterministic, i.e. the key might have |
923 | different values on different nodes. |
928 | different values on different nodes. |