Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def put(self, key, store_position, store):
while(True):
if(self.live_index.get_load() * 100.0 / self.config.INDEX_CAPACITY > self.config.INDEX_LOAD_FACTOR):
self.live_index.flush()
self.index_id += 1
self.logger.info("Index load reached, creating new index file: "+str(self.index_id))
self.index_list.append(Index(self.table, self.config, self.logger, self.index_id))
self.live_index = self.index_list[self.index_id]
self.live_index_usage = self.live_index.get_load()
resp = self.live_index.put(key, store_position, store)
if(resp != None):
self.logger.debug("Key: "+key+" indexed in: "+self.live_index.name)
break
def __init__(self, table, config, logger):
self.table = table
self.config = config
self.logger = logger
self.index_list = []
self.index_id = 0
self.load_indexes()
#if no index currenlty exist, create new live index.
if(len(self.index_list) == 0 ):
self.index_list.append(Index(table, config, logger, self.index_id))
self.live_index = self.index_list[self.index_id]
def load_indexes(self):
for f in os.listdir(self.config.cog_data_dir(self.table.db_name)):
if(self.config.INDEX in f):
self.logger.info("Loading index "+f)
id = self.config.index_id(f)
index = Index(self.table, self.config, self.logger, id)
self.index_list.append(index)
#make the latest index the live index.
if(id >= self.index_id):
self.index_id = id
self.live_index = index