How to use the lmdb.BadValsizeError function in lmdb

To help you get started, we’ve selected a few lmdb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tensorwerk / hangar-py / src / hangar / records / commiting.py View on Github external
Raises
    ------
    ValueError
        if no commit exists with the provided hash
    """
    reftxn = TxnRegister().begin_reader_txn(refenv)
    try:
        cmtRefKey = parsing.commit_ref_db_key_from_raw_key(commit_hash)
        cmtSpecKey = parsing.commit_spec_db_key_from_raw_key(commit_hash)
        cmtParentKey = parsing.commit_parent_db_key_from_raw_key(commit_hash)

        cmtRefVal = reftxn.get(cmtRefKey, default=False)
        cmtSpecVal = reftxn.get(cmtSpecKey, default=False)
        cmtParentVal = reftxn.get(cmtParentKey, default=False)
    except lmdb.BadValsizeError:
        raise ValueError(f'No commit exists with the hash: {commit_hash}')
    finally:
        TxnRegister().abort_reader_txn(refenv)

    if (cmtRefVal is False) or (cmtSpecVal is False) or (cmtParentVal is False):
        raise ValueError(f'No commit exists with the hash: {commit_hash}')

    commitRefs = parsing.commit_ref_raw_val_from_db_val(cmtRefVal)
    commitSpecs = parsing.commit_spec_raw_val_from_db_val(cmtSpecVal)
    commitParent = parsing.commit_parent_raw_val_from_db_val(cmtParentVal)

    calculatedDigest = parsing.cmt_final_digest(
        parent_digest=commitParent.digest,
        spec_digest=commitSpecs.digest,
        refs_digest=commitRefs.digest)
github hyperledger / sawtooth-core / validator / sawtooth_validator / database / indexed_database.py View on Github external
index_cursor = txn.cursor(index_db)

            for key in keys:
                read_key = key.encode()
                # If we're looking at an index, check the index first
                if index_cursor:
                    try:
                        read_key = index_cursor.get(read_key)
                    except lmdb.BadValsizeError:
                        raise KeyError("Invalid key: %s" % read_key)
                    if not read_key:
                        continue

                try:
                    packed = cursor.get(read_key)
                except lmdb.BadValsizeError:
                    raise KeyError("Invalid key: %s" % read_key)

                if packed is not None:
                    result.append((read_key.decode(),
                                   self._deserializer(packed)))
                elif index_cursor:
                    raise IndexOutOfSyncError(
                        'Index is out of sync for key {}'.format(key))

        return result
github SeanTater / uncc2014watsonsim / scripts / gensim / vstore.py View on Github external
def load(self, gen):
		''' Put() into the database many (name, vector) pairs '''
		with self._txn(write=True) as txn:
			try:
				for name, value in gen:
					txn.put(name, numpy.getbuffer(value))
			except lmdb.BadValsizeError as e:
				print name, value.shape, value