MCPcopy Create free account
hub / github.com/BIT-DataLab/LakeBench / CassandraStorage

Class CassandraStorage

join/LSH/datasketch/storage.py:701–798  ·  view source on GitHub ↗

Storage implementation using Cassandra. Note: like other implementations, each storage has its own client. Unlike other implementations, all storage instances share one session and can potentially share the same buffer.

Source from the content-addressed store, hash-verified

699
700
701 class CassandraStorage(object):
702 """
703 Storage implementation using Cassandra.
704
705 Note: like other implementations, each storage has its own client. Unlike other
706 implementations, all storage instances share one session and can potentially share the
707 same buffer.
708 """
709
710 DEFAULT_BUFFER_SIZE = 5000
711
712 def __init__(self, config, name=None, buffer_size=None):
713 """
714 Constructor.
715
716 :param dict[str, any] config: configuration following the following format:
717 {
718 'basename': b'test',
719 'type': 'cassandra',
720 'cassandra': {
721 'seeds': ['127.0.0.1'],
722 'keyspace': 'lsh_test',
723 'replication': {
724 'class': 'SimpleStrategy',
725 'replication_factor': '1'
726 },
727 'drop_keyspace': True,
728 'drop_tables': True,
729 'shared_buffer': False,
730 }
731 }
732 :param bytes name: the name
733 :param int buffer_size: the buffer size
734 """
735 self._config = config
736 if buffer_size is None:
737 buffer_size = CassandraStorage.DEFAULT_BUFFER_SIZE
738 cassandra_param = self._parse_config(self._config['cassandra'])
739 self._name = name if name else _random_name(11).decode('utf-8')
740 self._buffer_size = buffer_size
741 self._client = CassandraClient(cassandra_param, name, self._buffer_size)
742
743 @staticmethod
744 def _parse_config(config):
745 """
746 Parse a configuration dictionary, optionally fetching data from env variables.
747
748 :param dict[str, any] config: the configuration
749 :rtype: dict[str, str]
750 :return: the parse configuration
751 """
752 cfg = {}
753 for key, value in config.items():
754 if isinstance(value, dict):
755 if 'env' in value:
756 value = os.getenv(value['env'], value.get('default', None))
757 cfg[key] = value
758 return cfg

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected