Azure / azure-documentdb-java

Java Sync SDK for SQL API of Azure Cosmos DB
MIT License
47 stars 47 forks source link

query collection with collection id failed after re-creation #80

Open yungez opened 7 years ago

yungez commented 7 years ago

sdk version: 1.11.0 java version: 1.8 repro steps:

  1. create collection with collectionId : testCollection
  2. delete testCollection
  3. re-create testCollection, insert some documents
  4. query documents with testCollection by DocumentClient.QueryDocuments
    • if query collectionLink= "dbs//colls/testCollection", query failed with resource not found exception
    • if query collectionLink=collection.getSelfLink(), query succeed.

Question:

  1. in readme file, query document from collection with collection link "dbs//colls/". If this is not a bug, user should not query with self-constructed collection link, pls update document to avoid confusion.
  2. otherwise, pls check whether this is a bug.

anything info need feel free to ping me. thanks.

alfanse commented 6 years ago

as a tester, I do this a-lot on the integration environments. I've noticed its faster to drop collections and recreate than delete the 1000+ records individually. With query failing to read once a collection has been dropped and recreated I find this very frustrating.

We have coded around this with:

private List<Document> retrieveWithDocumentClientExceptionFailover(Exception e, Integer... productsIDs) {
        if (e.getCause().toString().contains("StatusCode: InvalidPartition")) {
            logger.info("Catching IllegalStateException thrown by queryDocument function when Azure collection is recreated after this app is started");
            documentClient = configuration.createDocumentClient();
            return documentClient.queryDocuments(collectionLink(databaseName, collectionName),
                    StoreUtils.findObjectsByIds(collectionName, productsIDs),
                    new FeedOptions()).getQueryIterable().toList();
        }
       return null;
    }

But find this very unsatisfactory...

Watching this thread with interest.