Exemple #1
0
 def test_create_from_at_rest(self):
     first_block = create_l1_block()
     second_block = l1_block_model.new_from_stripped_block(
         first_block.export_as_at_rest())
     # Need to remove transactions from original block (only stripped exist) for verification
     first_block.transactions = []
     self.assertDictEqual(first_block.__dict__, second_block.__dict__)
Exemple #2
0
def _generate_block_indexes_from_scratch() -> None:
    client = _get_redisearch_index_client(Indexes.block.value)
    client.create_index([
        redisearch.NumericField("block_id", sortable=True),
        redisearch.NumericField("prev_id", sortable=True),
        redisearch.NumericField("timestamp", sortable=True),
    ])
    _log.info("Listing all blocks in storage")
    block_paths = storage.list_objects("BLOCK/")
    pattern = re.compile(r"BLOCK\/[0-9]+$")
    for block_path in block_paths:
        if re.search(pattern, block_path):
            _log.info(f"Adding index for {block_path}")
            raw_block = storage.get_json_from_object(block_path)
            block = cast("model.BlockModel", None)
            if LEVEL == "1":
                block = l1_block_model.new_from_stripped_block(raw_block)
            elif LEVEL == "2":
                block = l2_block_model.new_from_at_rest(raw_block)
            elif LEVEL == "3":
                block = l3_block_model.new_from_at_rest(raw_block)
            elif LEVEL == "4":
                block = l4_block_model.new_from_at_rest(raw_block)
            elif LEVEL == "5":
                block = l5_block_model.new_from_at_rest(raw_block)
            put_document(Indexes.block.value, block.block_id,
                         block.export_as_search_index())
Exemple #3
0
def get_next_l1_block() -> Optional[l1_block_model.L1BlockModel]:
    """Get (and pop) the next l1 block to process off the queue"""
    if LEVEL != "2":
        raise RuntimeError("Getting next l1 block from queue is a level 2 action")

    next_item = get_next_item()

    if not next_item:
        return None

    return l1_block_model.new_from_stripped_block(next_item)
Exemple #4
0
def _generate_block_indexes() -> None:
    client = _get_redisearch_index_client(Indexes.block.value)
    try:
        client.create_index([
            redisearch.NumericField("block_id", sortable=True),
            redisearch.NumericField("prev_id", sortable=True),
            redisearch.NumericField("timestamp", sortable=True),
        ])
    except redis.exceptions.ResponseError as e:
        if not str(e).startswith("Index already exists"
                                 ):  # We don't care if index already exists
            raise
    _log.info("Listing all blocks in storage")
    block_paths = storage.list_objects("BLOCK/")
    pattern = re.compile(r"BLOCK\/[0-9]+$")
    for block_path in block_paths:
        if re.search(pattern, block_path):
            # do a check to see if this block was already marked as indexed
            if not client.redis.sismember(BLOCK_MIGRATION_KEY, block_path):
                _log.info(f"Adding index for {block_path}")
                raw_block = storage.get_json_from_object(block_path)
                block = cast("model.BlockModel", None)
                if LEVEL == "1":
                    block = l1_block_model.new_from_stripped_block(raw_block)
                elif LEVEL == "2":
                    block = l2_block_model.new_from_at_rest(raw_block)
                elif LEVEL == "3":
                    block = l3_block_model.new_from_at_rest(raw_block)
                elif LEVEL == "4":
                    block = l4_block_model.new_from_at_rest(raw_block)
                elif LEVEL == "5":
                    block = l5_block_model.new_from_at_rest(raw_block)
                put_document(Indexes.block.value, block.block_id,
                             block.export_as_search_index())
                client.redis.sadd(BLOCK_MIGRATION_KEY, block_path)
            else:
                _log.info(f"Skipping already indexed block {block_path}")