Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

populate metadataDB if empty #75

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
}