I am setting the TTL on my Cosmos Container to 1 to force the deletion of all items, I then query SELECT VALUE COUNT(1) from c to check that all items are deleted before setting TTL back to its previous value.
My issue is, I can see via the portal that the items are deleted but my query via the SDK returns the "old" wrong value for an inordinate time. Is there a way to force it to read the "real" value from the back end or establish a fresh connection etc?
//I create my client like so, setting Consistencylevel.STRONG will throw an error as
//it is higher level than the DB
CosmosClient cosmosClient= new CosmosClientBuilder().endpoint(DATABASE_HOST)
.key(DATABASE_KEY)
.consistencyLevel(ConsistencyLevel.SESSION)
.contentResponseOnWriteEnabled(true)
.buildClient();
//get the database
CosmosDatabase dataBase = cosmosClient.getDatabase(databaseName);
return dataBase;
//get the container
CosmosContainer container = theDatabase.getContainer(containerProps.getId());#
//update the TTL
containerProps.setDefaultTimeToLiveInSeconds(1);
container.replace(containerProps);
Thread.sleep(1000);
//now confirm that the container contents are deleted
//i tried refreshing my client/db/container objects to see if it would help
CosmosClient refreshedCosmosClient = createSyncCosmosClient();
CosmosDatabase refreshedDatabase = refreshedCosmosClient.getDatabase(DATABASE_NAME);
CosmosContainer refreshedContainer = refreshedDatabase.getContainer(container.getId());
//query the number of ITEMS in the container
CosmosPagedIterable<JsonNode> countOfDocs =
refreshedContainer.queryItems(CHECK_CONTAINER_EMPTY_QUERY, new CosmosQueryRequestOptions(),
JsonNode.class);
context.getLogger().info("wooooooooooooooooaaaa" +countOfDocs.toString());
//THIS VALUE IS NOT UP TO DATE. IT IS THE OLD VALUE
JsonNode count = countOfDocs.iterator().next();
int numberOfDocuments = count.asInt();
I can set the
ConsistencyLeveltoBOUNDED_STALENESS@5 seconds, this seems to improve things. I cannot useConsistencyLevel.STRONG*due to DB configuration