def create(connection): """Create dynamodb tables. """ Table.create(config.table_name('metric_names'), schema=[HashKey('domain'), RangeKey('name')], throughput=Schema.metric_names_tp, connection=connection) Table.create(config.table_name('tag_names'), schema=[HashKey('domain'), RangeKey('name')], throughput=Schema.tag_names_tp, connection=connection) Table.create(config.table_name('tag_values'), schema=[HashKey('domain'), RangeKey('value')], throughput=Schema.tag_values_tp, connection=connection) DatapointsSchema.create(connection)
def delete(connection): for block in DatapointsSchema(connection).blocks: block.delete_tables() try: Table(config.table_name('dp_master'), connection=connection).delete() except: pass
def __init__(self, connection): self.connection = connection self.master = Table(config.table_name('dp_master'), connection=connection) self.blocks = [ Block(self.master, connection, n) for n in range(BLOCKS) ] self.mx_worker = MaintenanceWorker(self)
def create_tables(self): """Create tables. """ if self.data_points_table and self.index_table: return self.state self.item['data_points_name'] = '%s_%s' % (config.table_name('dp'), self.tbase) self.item['index_name'] = '%s_%s' % (config.table_name('dp_index'), self.tbase) try: self.bind() except: if not self.data_points_table: Table.create(self.data_points_name, schema=[ HashKey('domain_metric_tbase_tags'), RangeKey('toffset', data_type=NUMBER) ], throughput={ 'read': config.get().TP_READ_DATAPOINTS / BLOCKS, 'write': config.get().TP_WRITE_DATAPOINTS }, connection=self.connection) if not self.index_table: Table.create( self.index_name, schema=[HashKey('domain_metric'), RangeKey('tbase_tags')], throughput={ 'read': config.get().TP_READ_INDEX_KEY / BLOCKS, 'write': config.get().TP_WRITE_INDEX_KEY }, connection=self.connection) self.item['state'] = self.bind() self.item.save(overwrite=True) return self.state
def create(connection, max_wait=120): master = Table.create(config.table_name('dp_master'), schema=[ HashKey('n', data_type=NUMBER), RangeKey('tbase', data_type=NUMBER) ], throughput={ 'read': 5, 'write': 5 }, connection=connection) wait_for_active(master, max_wait) now = util.now() for i in range(BLOCKS): next_block = now + i * BLOCK_SIZE master.put_item({ 'n': block_pos(next_block), 'tbase': base_time(next_block), 'state': 'INITIAL' })