container.move(name, newName); assertThat(container.listBlobsByPrefix(name).size(), equalTo(0)); blobs = container.listBlobsByPrefix(newName);
/** * Writes blob in atomic manner with resolving the blob name using {@link #blobName} and {@link #tempBlobName} methods. * <p> * The blob will be compressed and checksum will be written if required. * * Atomic move might be very inefficient on some repositories. It also cannot override existing files. * * @param obj object to be serialized * @param blobContainer blob container * @param name blob name */ public void writeAtomic(T obj, BlobContainer blobContainer, String name) throws IOException { String blobName = blobName(name); String tempBlobName = tempBlobName(name); writeBlob(obj, blobContainer, tempBlobName); try { blobContainer.move(tempBlobName, blobName); } catch (IOException ex) { // Move failed - try cleaning up blobContainer.deleteBlob(tempBlobName); throw ex; } }
/** * Writes blob in atomic manner with resolving the blob name using {@link #blobName} and {@link #tempBlobName} methods. * <p> * The blob will be compressed and checksum will be written if required. * * Atomic move might be very inefficient on some repositories. It also cannot override existing files. * * @param obj object to be serialized * @param blobContainer blob container * @param name blob name */ public void writeAtomic(T obj, BlobContainer blobContainer, String name) throws IOException { String blobName = blobName(name); String tempBlobName = tempBlobName(name); writeBlob(obj, blobContainer, tempBlobName); try { blobContainer.move(tempBlobName, blobName); } catch (IOException ex) { // Move failed - try cleaning up blobContainer.deleteBlob(tempBlobName); throw ex; } }
private void writeAtomic(final String blobName, final BytesReference bytesRef) throws IOException { final String tempBlobName = "pending-" + blobName + "-" + UUIDs.randomBase64UUID(); try (InputStream stream = bytesRef.streamInput()) { snapshotsBlobContainer.writeBlob(tempBlobName, stream, bytesRef.length()); snapshotsBlobContainer.move(tempBlobName, blobName); } catch (IOException ex) { // temporary blob creation or move failed - try cleaning up try { snapshotsBlobContainer.deleteBlob(tempBlobName); } catch (IOException e) { ex.addSuppressed(e); } throw ex; } }
@Override public String startVerification() { try { if (readOnly()) { // It's readonly - so there is not much we can do here to verify it return null; } else { String seed = Strings.randomBase64UUID(); byte[] testBytes = Strings.toUTF8Bytes(seed); BlobContainer testContainer = blobStore().blobContainer(basePath().add(testBlobPrefix(seed))); String blobName = "master.dat"; testContainer.writeBlob(blobName + "-temp", new BytesArray(testBytes)); // Make sure that move is supported testContainer.move(blobName + "-temp", blobName); return seed; } } catch (IOException exp) { throw new RepositoryVerificationException(repositoryName, "path " + basePath() + " is not accessible on master node", exp); } }
@Override public String startVerification() { try { if (isReadOnly()) { // It's readonly - so there is not much we can do here to verify it return null; } 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.writeBlob(blobName + "-temp", stream, bytes.length()); } // Make sure that move is supported testContainer.move(blobName + "-temp", blobName); return seed; } } catch (IOException exp) { throw new RepositoryVerificationException(metadata.name(), "path " + basePath() + " is not accessible on master node", exp); } }