Context(SnapshotId snapshotId, IndexId indexId, ShardId shardId, ShardId snapshotShardId) { this.snapshotId = snapshotId; this.shardId = shardId; blobContainer = blobStore().blobContainer(basePath().add("indices").add(indexId.getId()).add(Integer.toString(snapshotShardId.getId()))); }
@Override public void endVerification(String seed) { if (isReadOnly() == false) { try { blobStore().delete(basePath().add(testBlobPrefix(seed))); } catch (IOException exp) { throw new RepositoryVerificationException(metadata.name(), "cannot delete test data at " + basePath(), exp); } } }
@Override protected void doClose() { BlobStore store; // to close blobStore if blobStore initialization is started during close synchronized (lock) { store = blobStore.get(); } if (store != null) { try { store.close(); } catch (Exception t) { logger.warn("cannot close blob store", t); } } }
public void testContainerCreationAndDeletion() throws IOException { try(BlobStore store = newBlobStore()) { final BlobContainer containerFoo = store.blobContainer(new BlobPath().add("foo")); final BlobContainer containerBar = store.blobContainer(new BlobPath().add("bar")); byte[] data1 = randomBytes(randomIntBetween(10, scaledRandomIntBetween(1024, 1 << 16))); byte[] data2 = randomBytes(randomIntBetween(10, scaledRandomIntBetween(1024, 1 << 16))); writeBlob(containerFoo, "test", new BytesArray(data1)); writeBlob(containerBar, "test", new BytesArray(data2)); assertArrayEquals(readBlobFully(containerFoo, "test", data1.length), data1); assertArrayEquals(readBlobFully(containerBar, "test", data2.length), data2); assertTrue(containerFoo.blobExists("test")); assertTrue(containerBar.blobExists("test")); store.delete(new BlobPath()); assertFalse(containerFoo.blobExists("test")); assertFalse(containerBar.blobExists("test")); } }
@Override public IndexMetaData getSnapshotIndexMetaData(final SnapshotId snapshotId, final IndexId index) throws IOException { final BlobPath indexPath = basePath().add("indices").add(index.getId()); return indexMetaDataFormat.read(blobStore().blobContainer(indexPath), snapshotId.getUUID()); }
@Override public void endVerification(String seed) { if (readOnly()) { throw new UnsupportedOperationException("shouldn't be called"); } try { blobStore().delete(basePath().add(testBlobPrefix(seed))); } catch (IOException exp) { throw new RepositoryVerificationException(repositoryName, "cannot delete test data at " + basePath(), exp); } }
@Override protected void doClose() { try { blobStore().close(); } catch (Exception t) { logger.warn("cannot close blob store", t); } }
private void deleteIndexMetaDataBlobIgnoringErrors(final SnapshotInfo snapshotInfo, final IndexId indexId) { final SnapshotId snapshotId = snapshotInfo.snapshotId(); BlobContainer indexMetaDataBlobContainer = blobStore().blobContainer(basePath().add("indices").add(indexId.getId())); try { indexMetaDataFormat.delete(indexMetaDataBlobContainer, snapshotId.getUUID()); } catch (IOException ex) { logger.warn(() -> new ParameterizedMessage("[{}] failed to delete metadata for index [{}]", snapshotId, indexId.getName()), ex); } }
@Override public void endVerification(String seed) { if (isReadOnly()) { throw new UnsupportedOperationException("shouldn't be called"); } try { blobStore().delete(basePath().add(testBlobPrefix(seed))); } catch (IOException exp) { throw new RepositoryVerificationException(metadata.name(), "cannot delete test data at " + basePath(), exp); } }
@Override protected void doClose() { BlobStore store; // to close blobStore if blobStore initialization is started during close synchronized (lock) { store = blobStore.get(); } if (store != null) { try { store.close(); } catch (Exception t) { logger.warn("cannot close blob store", t); } } }
/** * maintains single lazy instance of {@link BlobContainer} */ protected BlobContainer blobContainer() { assertSnapshotOrGenericThread(); BlobContainer blobContainer = this.blobContainer.get(); if (blobContainer == null) { synchronized (lock) { blobContainer = this.blobContainer.get(); if (blobContainer == null) { blobContainer = blobStore().blobContainer(basePath()); this.blobContainer.set(blobContainer); } } } return blobContainer; }
@Override public void endVerification(String seed) { if (isReadOnly()) { throw new UnsupportedOperationException("shouldn't be called"); } try { blobStore().delete(basePath().add(testBlobPrefix(seed))); } catch (IOException exp) { throw new RepositoryVerificationException(metadata.name(), "cannot delete test data at " + basePath(), exp); } }
@Override protected void doClose() { BlobStore store; // to close blobStore if blobStore initialization is started during close synchronized (lock) { store = blobStore.get(); } if (store != null) { try { store.close(); } catch (Exception t) { logger.warn("cannot close blob store", t); } } }
final BlobContainer indicesBlobContainer = blobStore().blobContainer(basePath().add("indices")); for (final IndexId indexId : indicesToCleanUp) { try {
@Override public void endVerification(String seed) { if (isReadOnly()) { throw new UnsupportedOperationException("shouldn't be called"); } try { blobStore().delete(basePath().add(testBlobPrefix(seed))); } catch (IOException exp) { throw new RepositoryVerificationException(metadata.name(), "cannot delete test data at " + basePath(), exp); } }
/** * {@inheritDoc} */ @Override protected void doClose() { try { blobStore().close(); } catch (Throwable t) { logger.warn("cannot close blob store", t); } }
@Override public void initializeSnapshot(SnapshotId snapshotId, List<IndexId> indices, MetaData clusterMetaData) { if (isReadOnly()) { throw new RepositoryException(metadata.name(), "cannot create snapshot in a readonly repository"); } try { final String snapshotName = snapshotId.getName(); // check if the snapshot name already exists in the repository final RepositoryData repositoryData = getRepositoryData(); if (repositoryData.getAllSnapshotIds().stream().anyMatch(s -> s.getName().equals(snapshotName))) { throw new InvalidSnapshotNameException(metadata.name(), snapshotId.getName(), "snapshot with the same name already exists"); } if (snapshotFormat.exists(blobContainer(), snapshotId.getUUID())) { throw new InvalidSnapshotNameException(metadata.name(), snapshotId.getName(), "snapshot with the same name already exists"); } // Write Global MetaData globalMetaDataFormat.write(clusterMetaData, blobContainer(), snapshotId.getUUID()); // write the index metadata for each index in the snapshot for (IndexId index : indices) { final IndexMetaData indexMetaData = clusterMetaData.index(index.getName()); final BlobPath indexPath = basePath().add("indices").add(index.getId()); final BlobContainer indexMetaDataBlobContainer = blobStore().blobContainer(indexPath); indexMetaDataFormat.write(indexMetaData, indexMetaDataBlobContainer, snapshotId.getUUID()); } } catch (IOException ex) { throw new SnapshotCreationException(metadata.name(), snapshotId, ex); } }
@Override public String startVerification() { try { if (isReadOnly()) { // It's readonly - so there is not much we can do here to verify it apart from reading the blob store metadata latestIndexBlobId(); return "read-only"; } else { String seed = UUIDs.randomBase64UUID(); byte[] testBytes = Strings.toUTF8Bytes(seed); BlobContainer testContainer = blobStore().blobContainer(basePath().add(testBlobPrefix(seed))); String blobName = "master.dat"; BytesArray bytes = new BytesArray(testBytes); try (InputStream stream = bytes.streamInput()) { testContainer.writeBlobAtomic(blobName, stream, bytes.length(), true); } return seed; } } catch (IOException exp) { throw new RepositoryVerificationException(metadata.name(), "path " + basePath() + " is not accessible on master node", exp); } }
@Override public void verify(String seed, DiscoveryNode localNode) { assertSnapshotOrGenericThread(); if (isReadOnly()) { try { latestIndexBlobId(); } catch (IOException e) { throw new RepositoryVerificationException(metadata.name(), "path " + basePath() + " is not accessible on node " + localNode, e); } } else { BlobContainer testBlobContainer = blobStore().blobContainer(basePath().add(testBlobPrefix(seed))); if (testBlobContainer.blobExists("master.dat")) { try { BytesArray bytes = new BytesArray(seed); try (InputStream stream = bytes.streamInput()) { testBlobContainer.writeBlob("data-" + localNode.getId() + ".dat", stream, bytes.length(), true); } } catch (IOException exp) { throw new RepositoryVerificationException(metadata.name(), "store location [" + blobStore() + "] is not accessible on the node [" + localNode + "]", exp); } } else { throw new RepositoryVerificationException(metadata.name(), "a file written by master to the store [" + blobStore() + "] cannot be accessed on the node [" + localNode + "]. " + "This might indicate that the store [" + blobStore() + "] is not shared between this node and the master node or " + "that permissions on the store don't allow reading files written by the master node"); } } }
public Context(SnapshotId snapshotId, Version version, ShardId shardId, ShardId snapshotShardId) { this.snapshotId = snapshotId; this.version = version; this.shardId = shardId; blobContainer = blobStore.blobContainer(basePath.add("indices").add(snapshotShardId.getIndex()).add(Integer.toString(snapshotShardId.getId()))); }