Skip to content

Commit 99d210a

Browse files
authored
Update Azure internal blob store stats API to include operation purpose (#113573)
Closes ES-9549
1 parent 2eb9274 commit 99d210a

File tree

9 files changed

+400
-144
lines changed

9 files changed

+400
-144
lines changed

modules/repository-azure/src/internalClusterTest/java/org/elasticsearch/repositories/azure/AzureStorageCleanupThirdPartyTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.elasticsearch.common.Strings;
2424
import org.elasticsearch.common.UUIDs;
2525
import org.elasticsearch.common.blobstore.BlobContainer;
26+
import org.elasticsearch.common.blobstore.OperationPurpose;
2627
import org.elasticsearch.common.settings.MockSecureSettings;
2728
import org.elasticsearch.common.settings.SecureSettings;
2829
import org.elasticsearch.common.settings.Settings;
@@ -146,7 +147,8 @@ private void ensureSasTokenPermissions() {
146147
final PlainActionFuture<Void> future = new PlainActionFuture<>();
147148
repository.threadPool().generic().execute(ActionRunnable.wrap(future, l -> {
148149
final AzureBlobStore blobStore = (AzureBlobStore) repository.blobStore();
149-
final AzureBlobServiceClient azureBlobServiceClient = blobStore.getService().client("default", LocationMode.PRIMARY_ONLY);
150+
final AzureBlobServiceClient azureBlobServiceClient = blobStore.getService()
151+
.client("default", LocationMode.PRIMARY_ONLY, randomFrom(OperationPurpose.values()));
150152
final BlobServiceClient client = azureBlobServiceClient.getSyncClient();
151153
try {
152154
SocketAccess.doPrivilegedException(() -> {

modules/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureBlobContainer.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class AzureBlobContainer extends AbstractBlobContainer {
5151
@Override
5252
public boolean blobExists(OperationPurpose purpose, String blobName) throws IOException {
5353
logger.trace("blobExists({})", blobName);
54-
return blobStore.blobExists(buildKey(blobName));
54+
return blobStore.blobExists(purpose, buildKey(blobName));
5555
}
5656

5757
private InputStream openInputStream(OperationPurpose purpose, String blobName, long position, @Nullable Long length)
@@ -68,7 +68,7 @@ private InputStream openInputStream(OperationPurpose purpose, String blobName, l
6868
throw new NoSuchFileException("Blob [" + blobKey + "] not found");
6969
}
7070
try {
71-
return blobStore.getInputStream(blobKey, position, length);
71+
return blobStore.getInputStream(purpose, blobKey, position, length);
7272
} catch (Exception e) {
7373
if (ExceptionsHelper.unwrap(e, HttpResponseException.class) instanceof HttpResponseException httpResponseException) {
7474
final var httpStatusCode = httpResponseException.getResponse().getStatusCode();
@@ -102,7 +102,7 @@ public long readBlobPreferredLength() {
102102
public void writeBlob(OperationPurpose purpose, String blobName, InputStream inputStream, long blobSize, boolean failIfAlreadyExists)
103103
throws IOException {
104104
logger.trace("writeBlob({}, stream, {})", buildKey(blobName), blobSize);
105-
blobStore.writeBlob(buildKey(blobName), inputStream, blobSize, failIfAlreadyExists);
105+
blobStore.writeBlob(purpose, buildKey(blobName), inputStream, blobSize, failIfAlreadyExists);
106106
}
107107

108108
@Override
@@ -117,14 +117,13 @@ public void writeBlobAtomic(
117117
}
118118

119119
@Override
120-
public void writeBlobAtomic(OperationPurpose purpose, String blobName, BytesReference bytes, boolean failIfAlreadyExists)
121-
throws IOException {
120+
public void writeBlobAtomic(OperationPurpose purpose, String blobName, BytesReference bytes, boolean failIfAlreadyExists) {
122121
writeBlob(purpose, blobName, bytes, failIfAlreadyExists);
123122
}
124123

125124
@Override
126-
public void writeBlob(OperationPurpose purpose, String blobName, BytesReference bytes, boolean failIfAlreadyExists) throws IOException {
127-
blobStore.writeBlob(buildKey(blobName), bytes, failIfAlreadyExists);
125+
public void writeBlob(OperationPurpose purpose, String blobName, BytesReference bytes, boolean failIfAlreadyExists) {
126+
blobStore.writeBlob(purpose, buildKey(blobName), bytes, failIfAlreadyExists);
128127
}
129128

130129
@Override
@@ -135,12 +134,12 @@ public void writeMetadataBlob(
135134
boolean atomic,
136135
CheckedConsumer<OutputStream, IOException> writer
137136
) throws IOException {
138-
blobStore.writeBlob(buildKey(blobName), failIfAlreadyExists, writer);
137+
blobStore.writeBlob(purpose, buildKey(blobName), failIfAlreadyExists, writer);
139138
}
140139

141140
@Override
142-
public DeleteResult delete(OperationPurpose purpose) throws IOException {
143-
return blobStore.deleteBlobDirectory(keyPath);
141+
public DeleteResult delete(OperationPurpose purpose) {
142+
return blobStore.deleteBlobDirectory(purpose, keyPath);
144143
}
145144

146145
@Override
@@ -161,7 +160,7 @@ public String next() {
161160
@Override
162161
public Map<String, BlobMetadata> listBlobsByPrefix(OperationPurpose purpose, @Nullable String prefix) throws IOException {
163162
logger.trace("listBlobsByPrefix({})", prefix);
164-
return blobStore.listBlobsByPrefix(keyPath, prefix);
163+
return blobStore.listBlobsByPrefix(purpose, keyPath, prefix);
165164
}
166165

167166
@Override
@@ -173,7 +172,7 @@ public Map<String, BlobMetadata> listBlobs(OperationPurpose purpose) throws IOEx
173172
@Override
174173
public Map<String, BlobContainer> children(OperationPurpose purpose) throws IOException {
175174
final BlobPath path = path();
176-
return blobStore.children(path);
175+
return blobStore.children(purpose, path);
177176
}
178177

179178
protected String buildKey(String blobName) {
@@ -199,7 +198,7 @@ private boolean skipIfNotPrimaryOnlyLocationMode(ActionListener<?> listener) {
199198
@Override
200199
public void getRegister(OperationPurpose purpose, String key, ActionListener<OptionalBytesReference> listener) {
201200
if (skipRegisterOperation(listener)) return;
202-
ActionListener.completeWith(listener, () -> blobStore.getRegister(buildKey(key), keyPath, key));
201+
ActionListener.completeWith(listener, () -> blobStore.getRegister(purpose, buildKey(key), keyPath, key));
203202
}
204203

205204
@Override
@@ -211,7 +210,14 @@ public void compareAndExchangeRegister(
211210
ActionListener<OptionalBytesReference> listener
212211
) {
213212
if (skipRegisterOperation(listener)) return;
214-
ActionListener.completeWith(listener, () -> blobStore.compareAndExchangeRegister(buildKey(key), keyPath, key, expected, updated));
213+
ActionListener.completeWith(
214+
listener,
215+
() -> blobStore.compareAndExchangeRegister(purpose, buildKey(key), keyPath, key, expected, updated)
216+
);
215217
}
216218

219+
// visible for testing
220+
AzureBlobStore getBlobStore() {
221+
return blobStore;
222+
}
217223
}

0 commit comments

Comments
 (0)