in azurecosmos/src/main/java/site/ycsb/db/AzureCosmosClient.java [358:412]
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
try {
long st = System.nanoTime();
CosmosContainer container = AzureCosmosClient.containerCache.get(table);
if (container == null) {
container = AzureCosmosClient.database.getContainer(table);
AzureCosmosClient.containerCache.put(table, container);
}
CosmosItemResponse<ObjectNode> response = container.readItem(key, new PartitionKey(key), ObjectNode.class);
ObjectNode node = response.getItem();
Map<String, String> stringResults = new HashMap<>(node.size());
if (fields == null) {
Iterator<Map.Entry<String, JsonNode>> iter = node.fields();
while (iter.hasNext()) {
Entry<String, JsonNode> pair = iter.next();
stringResults.put(pair.getKey().toString(), pair.getValue().toString());
}
StringByteIterator.putAllAsByteIterators(result, stringResults);
} else {
Iterator<Map.Entry<String, JsonNode>> iter = node.fields();
while (iter.hasNext()) {
Entry<String, JsonNode> pair = iter.next();
if (fields.contains(pair.getKey())) {
stringResults.put(pair.getKey().toString(), pair.getValue().toString());
}
}
StringByteIterator.putAllAsByteIterators(result, stringResults);
}
if (diagnosticsLatencyThresholdInMS > 0 &&
response.getDiagnostics().getDuration().compareTo(Duration.ofMillis(diagnosticsLatencyThresholdInMS)) > 0) {
LOGGER.warn(READ_DIAGNOSTIC, response.getDiagnostics().toString());
}
if (readSuccessLatencyTimer != null) {
long en = System.nanoTime();
long latency = (en - st) / 1000;
readSuccessLatencyTimer.record(latency, TimeUnit.MICROSECONDS);
readSuccessCounter.increment();
}
return Status.OK;
} catch (CosmosException e) {
int statusCode = e.getStatusCode();
if (!AzureCosmosClient.includeExceptionStackInLog) {
e = null;
}
LOGGER.error(READ_EXCEPTION, "Failed to read key {} in collection {} in database {} statusCode {}", key, table,
AzureCosmosClient.databaseName, statusCode, e);
if (readFailureCounter != null) {
readFailureCounter.increment();
}
return Status.NOT_FOUND;
}
}