Skip to content

Commit

Permalink
populate metadataDB if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
kevodwyer committed Nov 10, 2023
1 parent 917440e commit 1d3b443
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/main/java/org/peergos/EmbeddedIpfs.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,18 @@ public static BlockMetadataStore buildBlockMetadata(Args a) {
}
}
public static Blockstore buildBlockStore(Config config, Path ipfsPath, BlockMetadataStore meta) {
Blockstore blocks;
Blockstore withMetadb;
if (config.datastore.blockMount.prefix.equals("flatfs.datastore")) {
blocks = new FileBlockstore(ipfsPath);
CachingBlockMetadataStore cachedBlocks = new CachingBlockMetadataStore(new FileBlockstore(ipfsPath), meta);
cachedBlocks.updateMetadataStoreIfEmpty();
withMetadb = cachedBlocks;
} else if (config.datastore.blockMount.prefix.equals("s3.datastore")) {
S3Blockstore s3blocks = new S3Blockstore(config.datastore.blockMount.getParams(), meta);
blocks = s3blocks;
s3blocks.updateMetadataStoreIfEmpty();
withMetadb = s3blocks;
} else {
throw new IllegalStateException("Unrecognized datastore prefix: " + config.datastore.blockMount.prefix);
}
Blockstore withMetadb = config.datastore.blockMount.prefix.equals("s3.datastore") ?
blocks :
new CachingBlockMetadataStore(blocks, meta);

return typeLimited(filteredBlockStore(withMetadb, config), config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,15 @@ public CompletableFuture<Boolean> rm(Cid c) {
return res;
});
}

public void updateMetadataStoreIfEmpty() {
if (metadata.size() > 0)
return;
List<Cid> cids = target.refs().join();
for(Cid c : cids) {
Optional<BlockMetadata> existing = metadata.get(c);
if (existing.isEmpty())
metadata.put(c, target.getBlockMetadata(c).join());
}
}
}

0 comments on commit 1d3b443

Please sign in to comment.