|
@@ -53,11 +53,9 @@ import org.elasticsearch.common.blobstore.BlobStore;
|
|
|
import org.elasticsearch.common.blobstore.DeleteResult;
|
|
|
import org.elasticsearch.common.blobstore.fs.FsBlobContainer;
|
|
|
import org.elasticsearch.common.bytes.BytesArray;
|
|
|
-import org.elasticsearch.common.bytes.BytesReference;
|
|
|
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
|
|
import org.elasticsearch.common.compress.NotXContentException;
|
|
|
import org.elasticsearch.common.io.Streams;
|
|
|
-import org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput;
|
|
|
import org.elasticsearch.common.lucene.Lucene;
|
|
|
import org.elasticsearch.common.lucene.store.InputStreamIndexInput;
|
|
|
import org.elasticsearch.common.metrics.CounterMetric;
|
|
@@ -74,6 +72,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
|
import org.elasticsearch.common.xcontent.XContentParser;
|
|
|
import org.elasticsearch.common.xcontent.XContentType;
|
|
|
+import org.elasticsearch.core.CheckedConsumer;
|
|
|
import org.elasticsearch.core.Nullable;
|
|
|
import org.elasticsearch.core.Releasable;
|
|
|
import org.elasticsearch.core.Tuple;
|
|
@@ -118,6 +117,7 @@ import org.elasticsearch.threadpool.ThreadPool;
|
|
|
import java.io.FilterInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.nio.file.NoSuchFileException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
@@ -553,15 +553,13 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
|
|
sourceMeta.asClone(target.getName(), startTime, threadPool.absoluteTimeInMillis() - startTime),
|
|
|
shardContainer,
|
|
|
target.getUUID(),
|
|
|
- compress,
|
|
|
- bigArrays
|
|
|
+ compress
|
|
|
);
|
|
|
INDEX_SHARD_SNAPSHOTS_FORMAT.write(
|
|
|
existingSnapshots.withClone(source.getName(), target.getName()),
|
|
|
shardContainer,
|
|
|
newGen,
|
|
|
- compress,
|
|
|
- bigArrays
|
|
|
+ compress
|
|
|
);
|
|
|
return new ShardSnapshotResult(
|
|
|
newGen,
|
|
@@ -1394,7 +1392,7 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
|
|
executor.execute(
|
|
|
ActionRunnable.run(
|
|
|
allMetaListener,
|
|
|
- () -> GLOBAL_METADATA_FORMAT.write(clusterMetadata, blobContainer(), snapshotId.getUUID(), compress, bigArrays)
|
|
|
+ () -> GLOBAL_METADATA_FORMAT.write(clusterMetadata, blobContainer(), snapshotId.getUUID(), compress)
|
|
|
)
|
|
|
);
|
|
|
|
|
@@ -1408,7 +1406,7 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
|
|
if (metaUUID == null) {
|
|
|
// We don't yet have this version of the metadata so we write it
|
|
|
metaUUID = UUIDs.base64UUID();
|
|
|
- INDEX_METADATA_FORMAT.write(indexMetaData, indexContainer(index), metaUUID, compress, bigArrays);
|
|
|
+ INDEX_METADATA_FORMAT.write(indexMetaData, indexContainer(index), metaUUID, compress);
|
|
|
indexMetaIdentifiers.put(identifiers, metaUUID);
|
|
|
}
|
|
|
indexMetas.put(index, identifiers);
|
|
@@ -1417,8 +1415,7 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
|
|
clusterMetadata.index(index.getName()),
|
|
|
indexContainer(index),
|
|
|
snapshotId.getUUID(),
|
|
|
- compress,
|
|
|
- bigArrays
|
|
|
+ compress
|
|
|
);
|
|
|
}
|
|
|
}));
|
|
@@ -1426,7 +1423,7 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
|
|
executor.execute(
|
|
|
ActionRunnable.run(
|
|
|
allMetaListener,
|
|
|
- () -> SNAPSHOT_FORMAT.write(snapshotInfo, blobContainer(), snapshotId.getUUID(), compress, bigArrays)
|
|
|
+ () -> SNAPSHOT_FORMAT.write(snapshotInfo, blobContainer(), snapshotId.getUUID(), compress)
|
|
|
)
|
|
|
);
|
|
|
}, onUpdateFailure);
|
|
@@ -2250,13 +2247,11 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
|
|
}
|
|
|
final String indexBlob = INDEX_FILE_PREFIX + Long.toString(newGen);
|
|
|
logger.debug("Repository [{}] writing new index generational blob [{}]", metadata.name(), indexBlob);
|
|
|
- try (ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(bigArrays)) {
|
|
|
+ writeAtomic(blobContainer(), indexBlob, out -> {
|
|
|
try (XContentBuilder xContentBuilder = XContentFactory.jsonBuilder(Streams.noCloseStream(out))) {
|
|
|
newRepositoryData.snapshotsToXContent(xContentBuilder, version);
|
|
|
}
|
|
|
- final BytesReference serializedRepoData = out.bytes();
|
|
|
- writeAtomic(blobContainer(), indexBlob, serializedRepoData, true);
|
|
|
- }
|
|
|
+ }, true);
|
|
|
maybeWriteIndexLatest(newGen);
|
|
|
|
|
|
// Step 3: Update CS to reflect new repository generation.
|
|
@@ -2349,7 +2344,7 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
|
|
if (supportURLRepo) {
|
|
|
logger.debug("Repository [{}] updating index.latest with generation [{}]", metadata.name(), newGen);
|
|
|
try {
|
|
|
- writeAtomic(blobContainer(), INDEX_LATEST_BLOB, new BytesArray(Numbers.longToBytes(newGen)), false);
|
|
|
+ writeAtomic(blobContainer(), INDEX_LATEST_BLOB, out -> out.write(Numbers.longToBytes(newGen)), false);
|
|
|
} catch (Exception e) {
|
|
|
logger.warn(
|
|
|
() -> new ParameterizedMessage(
|
|
@@ -2530,10 +2525,14 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
|
|
return latest;
|
|
|
}
|
|
|
|
|
|
- private void writeAtomic(BlobContainer container, final String blobName, final BytesReference bytesRef, boolean failIfAlreadyExists)
|
|
|
- throws IOException {
|
|
|
+ private void writeAtomic(
|
|
|
+ BlobContainer container,
|
|
|
+ final String blobName,
|
|
|
+ CheckedConsumer<OutputStream, IOException> writer,
|
|
|
+ boolean failIfAlreadyExists
|
|
|
+ ) throws IOException {
|
|
|
logger.trace(() -> new ParameterizedMessage("[{}] Writing [{}] to {} atomically", metadata.name(), blobName, container.path()));
|
|
|
- container.writeBlobAtomic(blobName, bytesRef, failIfAlreadyExists);
|
|
|
+ container.writeBlob(blobName, failIfAlreadyExists, true, writer);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -2684,13 +2683,7 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
|
|
// reference a generation that has not had all its files fully upload.
|
|
|
indexGeneration = UUIDs.randomBase64UUID();
|
|
|
try {
|
|
|
- INDEX_SHARD_SNAPSHOTS_FORMAT.write(
|
|
|
- updatedBlobStoreIndexShardSnapshots,
|
|
|
- shardContainer,
|
|
|
- indexGeneration,
|
|
|
- compress,
|
|
|
- bigArrays
|
|
|
- );
|
|
|
+ INDEX_SHARD_SNAPSHOTS_FORMAT.write(updatedBlobStoreIndexShardSnapshots, shardContainer, indexGeneration, compress);
|
|
|
} catch (IOException e) {
|
|
|
throw new IndexShardSnapshotFailedException(
|
|
|
shardId,
|
|
@@ -2767,7 +2760,7 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
|
|
);
|
|
|
try {
|
|
|
final String snapshotUUID = snapshotId.getUUID();
|
|
|
- INDEX_SHARD_SNAPSHOT_FORMAT.write(blobStoreIndexShardSnapshot, shardContainer, snapshotUUID, compress, bigArrays);
|
|
|
+ INDEX_SHARD_SNAPSHOT_FORMAT.write(blobStoreIndexShardSnapshot, shardContainer, snapshotUUID, compress);
|
|
|
} catch (IOException e) {
|
|
|
throw new IndexShardSnapshotFailedException(shardId, "Failed to write commit point", e);
|
|
|
}
|
|
@@ -3140,7 +3133,7 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
|
|
final BlobStoreIndexShardSnapshots updatedSnapshots = new BlobStoreIndexShardSnapshots(newSnapshotsList);
|
|
|
if (indexGeneration < 0L) {
|
|
|
writtenGeneration = UUIDs.randomBase64UUID();
|
|
|
- INDEX_SHARD_SNAPSHOTS_FORMAT.write(updatedSnapshots, shardContainer, writtenGeneration, compress, bigArrays);
|
|
|
+ INDEX_SHARD_SNAPSHOTS_FORMAT.write(updatedSnapshots, shardContainer, writtenGeneration, compress);
|
|
|
} else {
|
|
|
writtenGeneration = String.valueOf(indexGeneration);
|
|
|
writeShardIndexBlobAtomic(shardContainer, indexGeneration, updatedSnapshots);
|
|
@@ -3180,12 +3173,11 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
|
|
() -> new ParameterizedMessage("[{}] Writing shard index [{}] to [{}]", metadata.name(), indexGeneration, shardContainer.path())
|
|
|
);
|
|
|
final String blobName = INDEX_SHARD_SNAPSHOTS_FORMAT.blobName(String.valueOf(indexGeneration));
|
|
|
- INDEX_SHARD_SNAPSHOTS_FORMAT.serialize(
|
|
|
- updatedSnapshots,
|
|
|
+ writeAtomic(
|
|
|
+ shardContainer,
|
|
|
blobName,
|
|
|
- compress,
|
|
|
- bigArrays,
|
|
|
- bytes -> writeAtomic(shardContainer, blobName, bytes, true)
|
|
|
+ out -> INDEX_SHARD_SNAPSHOTS_FORMAT.serialize(updatedSnapshots, blobName, compress, out),
|
|
|
+ true
|
|
|
);
|
|
|
}
|
|
|
|