addr = engine.lookup(server_addr) provider_handle = client.create_provider_handle(addr, provider_id) db = provider_handle.open("mydatabase") db.put("matthieu", "*****@*****.**") val = db.get("matthieu") print("db.get('matthieu') returned " + str(val)) try: val = db.get("phil") print("db.get('phil') returned " + str(val)) except KeyError: print("Correctly throws an exception when trying to lookup 'phil'") e = db.exists("matthieu") print("db.exists('matthieu') returned " + str(e)) e = db.exists("phil") print("db.exists('phil') returned " + str(e)) db.erase("matthieu") try: val = db.get("matthieu") print("db.get('matthieu') returned " + str(val)) except KeyError: print("Correctly throws an exception when trying to lookup 'matthieu'") del db del provider_handle client.shutdown_service(addr) del addr del client engine.finalize()
region = ph.create(target, 32) print("Created region "+str(region)) regionstr = str(region) region = BakeRegionID.from_str(regionstr) print("reconverting region to string: "+str(region)) # write into the region ph.write(target, region, 0, 'A'*16) ph.write(target, region, 16, 'B'*16) # get size of region try: s = ph.get_size(target, region) print("Region size is "+str(s)) except: print("Getting region size is not supported") # persist region ph.persist(target, region, size=32) # read region result = ph.read(target, region, 8, 16) print("Reading region at offset 8, size 16 gives: "+str(result)) del ph client.shutdown_service(addr) del addr client.finalize() test() mid.finalize()
class ProvDB(): def __init__(self, pdb_path='', pdb_sharded_num=0, pdb_addr=''): if pdb_addr == '': # Standalone mode, need to create engine provider self.pdb_engine = Engine('ofi+tcp', mode=pymargo.server) self.pdb_provider = SonataProvider(self.pdb_engine, 0) self.pdb_address = str(self.pdb_engine.addr()) self.pdb_admin = SonataAdmin(self.pdb_engine) self.pdb_client = SonataClient(self.pdb_engine) if pdb_path and int(pdb_sharded_num) > 0: for i in range(int(pdb_sharded_num)): pdb_name = 'provdb.' + str(i) file_name = pdb_path + pdb_name + '.unqlite' self.pdb_admin.attach_database( self.pdb_address, 0, pdb_name, 'unqlite', "{ \"path\" : \"%s\" }" % file_name) else: # Other Chimbuko module created the engine self.pdb_engine = Engine(pdb_addr.split(':')[0], pymargo.client) self.pdb_address = pdb_addr self.pdb_client = SonataClient(self.pdb_engine) self.pdb_databases = [] self.pdb_collections = [] self.pdb_names = [] for i in range(pdb_sharded_num): pdb_name = 'provdb.' + str(i) self.pdb_names.append(pdb_name) database = self.pdb_client.open(self.pdb_address, 0, pdb_name) self.pdb_databases.append(database) col = database.open('anomalies') self.pdb_collections.append(col) # print("=-=-=-=-=Initiated ProvDB instance {}=-=-=-=-=".format( # self.pdb_address)) def __del__(self): if self.pdb_databases: for database in self.pdb_databases: del database database = None del self.pdb_databases self.pdb_databases = [] if self.pdb_collections: for col in self.pdb_collections: del col col = None del self.pdb_collections self.pdb_collections = [] if self.pdb_names: for name in self.pdb_names: if hasattr(self, 'pdb_admin'): self.pdb_admin.detach_database(self.pdb_address, 0, name) del name name = None self.pdb_names = [] if self.pdb_client: del self.pdb_client self.pdb_client = None if self.pdb_address: del self.pdb_address self.pdb_address = None if hasattr(self, 'pdb_admin') and self.pdb_admin: del self.pdb_admin self.pdb_admin = None if hasattr(self, 'pdb_provider') and self.pdb_provider: del self.pdb_provider self.pdb_provider = None if self.pdb_engine: self.pdb_engine.finalize() gc.collect() del self.pdb_engine self.pdb_engine = None