AzureArchiveManager implements SegmentArchiveManager { @Override public boolean delete(String archiveName) { try { getBlobs(archiveName) .forEach(cloudBlob -> { try { cloudBlob.delete(); } catch (StorageException e) { log.error("Can't delete segment {}", cloudBlob.getUri().getPath(), e); } }); return true; } catch (IOException e) { log.error("Can't delete archive {}", archiveName, e); return false; } } AzureArchiveManager(CloudBlobDirectory cloudBlobDirectory, IOMonitor ioMonitor, FileStoreMonitor fileStoreMonitor); @Override List<String> listArchives(); @Override SegmentArchiveReader open(String archiveName); @Override SegmentArchiveReader forceOpen(String archiveName); @Override SegmentArchiveWriter create(String archiveName); @Override boolean delete(String archiveName); @Override boolean renameTo(String from, String to); @Override void copyFile(String from, String to); @Override boolean exists(String archiveName); @Override void recoverEntries(String archiveName, LinkedHashMap<UUID, byte[]> entries); @Override void backup(@NotNull String archiveName, @NotNull String backupArchiveName, @NotNull Set<UUID> recoveredEntries);  }
@Test public void testUncleanStop() throws URISyntaxException, IOException, InvalidFileStoreVersionException, CommitFailedException, StorageException { AzurePersistence p = new AzurePersistence(container.getDirectoryReference("oak")); FileStore fs = FileStoreBuilder.fileStoreBuilder(new File("target")).withCustomPersistence(p).build(); SegmentNodeStore segmentNodeStore = SegmentNodeStoreBuilders.builder(fs).build(); NodeBuilder builder = segmentNodeStore.getRoot().builder(); builder.setProperty("foo", "bar"); segmentNodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); fs.close(); container.getBlockBlobReference("oak/data00000a.tar/closed").delete(); container.getBlockBlobReference("oak/data00000a.tar/data00000a.tar.brf").delete(); container.getBlockBlobReference("oak/data00000a.tar/data00000a.tar.gph").delete(); fs = FileStoreBuilder.fileStoreBuilder(new File("target")).withCustomPersistence(p).build(); segmentNodeStore = SegmentNodeStoreBuilders.builder(fs).build(); assertEquals("bar", segmentNodeStore.getRoot().getString("foo")); fs.close(); }
@Test public void testUncleanStopWithEmptyArchive() throws URISyntaxException, IOException, InvalidFileStoreVersionException, CommitFailedException, StorageException { AzurePersistence p = new AzurePersistence(container.getDirectoryReference("oak")); FileStore fs = FileStoreBuilder.fileStoreBuilder(new File("target")).withCustomPersistence(p).build(); SegmentNodeStore segmentNodeStore = SegmentNodeStoreBuilders.builder(fs).build(); NodeBuilder builder = segmentNodeStore.getRoot().builder(); builder.setProperty("foo", "bar"); segmentNodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); fs.close(); fs = FileStoreBuilder.fileStoreBuilder(new File("target")).withCustomPersistence(p).build(); segmentNodeStore = SegmentNodeStoreBuilders.builder(fs).build(); builder = segmentNodeStore.getRoot().builder(); builder.setProperty("foo2", "bar2"); segmentNodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); fs.close(); ListBlobItem segment0000 = container.listBlobs("oak/data00001a.tar/0000.").iterator().next(); ((CloudBlob) segment0000).delete(); container.getBlockBlobReference("oak/data00001a.tar/closed").delete(); fs = FileStoreBuilder.fileStoreBuilder(new File("target")).withCustomPersistence(p).build(); segmentNodeStore = SegmentNodeStoreBuilders.builder(fs).build(); assertEquals("bar", segmentNodeStore.getRoot().getString("foo")); fs.close(); }
@Test public void testUncleanStopSegmentMissing() throws URISyntaxException, IOException, InvalidFileStoreVersionException, CommitFailedException, StorageException { AzurePersistence p = new AzurePersistence(container.getDirectoryReference("oak")); FileStore fs = FileStoreBuilder.fileStoreBuilder(new File("target")).withCustomPersistence(p).build(); SegmentNodeStore segmentNodeStore = SegmentNodeStoreBuilders.builder(fs).build(); NodeBuilder builder = segmentNodeStore.getRoot().builder(); builder.setProperty("foo", "bar"); segmentNodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); fs.close(); fs = FileStoreBuilder.fileStoreBuilder(new File("target")).withCustomPersistence(p).build(); segmentNodeStore = SegmentNodeStoreBuilders.builder(fs).build(); builder = segmentNodeStore.getRoot().builder(); builder.setProperty("foo0", "bar0"); segmentNodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); fs.flush(); builder.setProperty("foo1", "bar1"); segmentNodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); fs.flush(); builder.setProperty("foo2", "bar2"); segmentNodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); fs.flush(); builder.setProperty("foo3", "bar3"); segmentNodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); fs.flush(); fs.close(); ListBlobItem segment0002 = container.listBlobs("oak/data00001a.tar/0002.").iterator().next(); ((CloudBlob) segment0002).delete(); container.getBlockBlobReference("oak/data00001a.tar/closed").delete(); fs = FileStoreBuilder.fileStoreBuilder(new File("target")).withCustomPersistence(p).build(); segmentNodeStore = SegmentNodeStoreBuilders.builder(fs).build(); assertEquals("bar", segmentNodeStore.getRoot().getString("foo")); assertFalse(container.listBlobs("oak/data00001a.tar/0002.").iterator().hasNext()); assertFalse(container.listBlobs("oak/data00001a.tar/0003.").iterator().hasNext()); assertTrue("Backup directory should have been created", container.listBlobs("oak/data00001a.tar.bak").iterator().hasNext()); assertTrue(container.listBlobs("oak/data00001a.tar.bak/0001.").iterator().hasNext()); assertFalse(container.listBlobs("oak/data00001a.tar.bak/0002.").iterator().hasNext()); assertTrue(container.listBlobs("oak/data00001a.tar.bak/0003.").iterator().hasNext()); assertEquals("bar1", segmentNodeStore.getRoot().getString("foo1")); assertNull(segmentNodeStore.getRoot().getString("foo2")); assertNull(segmentNodeStore.getRoot().getString("foo3")); fs.close(); }