Search in sources :

Example 1 with RateLimitingInputStream

use of org.elasticsearch.index.snapshots.blobstore.RateLimitingInputStream in project crate by crate.

the class BlobStoreRepository method snapshotFile.

/**
 * Snapshot individual file
 * @param fileInfo file to be snapshotted
 */
private void snapshotFile(BlobStoreIndexShardSnapshot.FileInfo fileInfo, IndexId indexId, ShardId shardId, SnapshotId snapshotId, IndexShardSnapshotStatus snapshotStatus, Store store) throws IOException {
    final BlobContainer shardContainer = shardContainer(indexId, shardId);
    final String file = fileInfo.physicalName();
    store.incRef();
    try (IndexInput indexInput = store.openVerifyingInput(file, IOContext.READONCE, fileInfo.metadata())) {
        for (int i = 0; i < fileInfo.numberOfParts(); i++) {
            final long partBytes = fileInfo.partBytes(i);
            InputStream inputStream = new InputStreamIndexInput(indexInput, partBytes);
            if (snapshotRateLimiter != null) {
                inputStream = new RateLimitingInputStream(inputStream, snapshotRateLimiter, snapshotRateLimitingTimeInNanos::inc);
            }
            // Make reads abortable by mutating the snapshotStatus object
            inputStream = new FilterInputStream(inputStream) {

                @Override
                public int read() throws IOException {
                    checkAborted();
                    return super.read();
                }

                @Override
                public int read(byte[] b, int off, int len) throws IOException {
                    checkAborted();
                    return super.read(b, off, len);
                }

                private void checkAborted() {
                    if (snapshotStatus.isAborted()) {
                        LOGGER.debug("[{}] [{}] Aborted on the file [{}], exiting", shardId, snapshotId, fileInfo.physicalName());
                        throw new IndexShardSnapshotFailedException(shardId, "Aborted");
                    }
                }
            };
            shardContainer.writeBlob(fileInfo.partName(i), inputStream, partBytes, true);
        }
        Store.verify(indexInput);
        snapshotStatus.addProcessedFile(fileInfo.length());
    } catch (Exception t) {
        failStoreIfCorrupted(store, t);
        snapshotStatus.addProcessedFile(0);
        throw t;
    } finally {
        store.decRef();
    }
}
Also used : FilterInputStream(java.io.FilterInputStream) RateLimitingInputStream(org.elasticsearch.index.snapshots.blobstore.RateLimitingInputStream) RateLimitingInputStream(org.elasticsearch.index.snapshots.blobstore.RateLimitingInputStream) FilterInputStream(java.io.FilterInputStream) SlicedInputStream(org.elasticsearch.index.snapshots.blobstore.SlicedInputStream) InputStream(java.io.InputStream) IndexShardSnapshotFailedException(org.elasticsearch.index.snapshots.IndexShardSnapshotFailedException) IOException(java.io.IOException) IndexShardSnapshotFailedException(org.elasticsearch.index.snapshots.IndexShardSnapshotFailedException) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) InvalidArgumentException(io.crate.exceptions.InvalidArgumentException) SnapshotException(org.elasticsearch.snapshots.SnapshotException) IOException(java.io.IOException) SnapshotMissingException(org.elasticsearch.snapshots.SnapshotMissingException) NoSuchFileException(java.nio.file.NoSuchFileException) ConcurrentSnapshotExecutionException(org.elasticsearch.snapshots.ConcurrentSnapshotExecutionException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) IndexShardRestoreFailedException(org.elasticsearch.index.snapshots.IndexShardRestoreFailedException) RepositoryException(org.elasticsearch.repositories.RepositoryException) NotXContentException(org.elasticsearch.common.compress.NotXContentException) IndexShardSnapshotException(org.elasticsearch.index.snapshots.IndexShardSnapshotException) RepositoryVerificationException(org.elasticsearch.repositories.RepositoryVerificationException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) BlobContainer(org.elasticsearch.common.blobstore.BlobContainer) FsBlobContainer(org.elasticsearch.common.blobstore.fs.FsBlobContainer) InputStreamIndexInput(org.elasticsearch.common.lucene.store.InputStreamIndexInput) InputStreamIndexInput(org.elasticsearch.common.lucene.store.InputStreamIndexInput) IndexInput(org.apache.lucene.store.IndexInput)

Aggregations

InvalidArgumentException (io.crate.exceptions.InvalidArgumentException)1 FilterInputStream (java.io.FilterInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)1 IndexFormatTooNewException (org.apache.lucene.index.IndexFormatTooNewException)1 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)1 IndexInput (org.apache.lucene.store.IndexInput)1 BlobContainer (org.elasticsearch.common.blobstore.BlobContainer)1 FsBlobContainer (org.elasticsearch.common.blobstore.fs.FsBlobContainer)1 NotXContentException (org.elasticsearch.common.compress.NotXContentException)1 InputStreamIndexInput (org.elasticsearch.common.lucene.store.InputStreamIndexInput)1 IndexShardRestoreFailedException (org.elasticsearch.index.snapshots.IndexShardRestoreFailedException)1 IndexShardSnapshotException (org.elasticsearch.index.snapshots.IndexShardSnapshotException)1 IndexShardSnapshotFailedException (org.elasticsearch.index.snapshots.IndexShardSnapshotFailedException)1 RateLimitingInputStream (org.elasticsearch.index.snapshots.blobstore.RateLimitingInputStream)1 SlicedInputStream (org.elasticsearch.index.snapshots.blobstore.SlicedInputStream)1 RepositoryException (org.elasticsearch.repositories.RepositoryException)1 RepositoryVerificationException (org.elasticsearch.repositories.RepositoryVerificationException)1