Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException on readDocument() #112

Open
mkozioro opened this issue May 7, 2018 · 2 comments
Open

NullPointerException on readDocument() #112

mkozioro opened this issue May 7, 2018 · 2 comments

Comments

@mkozioro
Copy link

mkozioro commented May 7, 2018

SDK Version: 1.16.0

We see following errors in logs:

java.lang.NullPointerException: null
        at com.microsoft.azure.documentdb.internal.SessionContainer.compareAndSetToken(SessionContainer.java:194)
        at com.microsoft.azure.documentdb.internal.SessionContainer.setSessionToken(SessionContainer.java:167)
        at com.microsoft.azure.documentdb.internal.SessionContainer.setSessionToken(SessionContainer.java:156)
        at com.microsoft.azure.documentdb.internal.SessionTokenHelper.captureSessionToken(SessionTokenHelper.java:138)
        at com.microsoft.azure.documentdb.DocumentClient.captureSessionToken(DocumentClient.java:3155)
        at com.microsoft.azure.documentdb.DocumentClient.doRead(DocumentClient.java:3054)
        at com.microsoft.azure.documentdb.DocumentClient.readDocument(DocumentClient.java:1041)
        at com.tomtom.lns.batch.dao.CosmosDBDao.getDocumentByBatchId(CosmosDBDao.java:358)
java.lang.NullPointerException: null
        at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
        at com.microsoft.azure.documentdb.internal.SessionContainer.getPartitionKeyRangeIdToTokenMap(SessionContainer.java:72)
        at com.microsoft.azure.documentdb.internal.SessionContainer.resolveGlobalSessionToken(SessionContainer.java:88)
        at com.microsoft.azure.documentdb.internal.SessionContainer.resolveGlobalSessionToken(SessionContainer.java:84)
        at com.microsoft.azure.documentdb.DocumentClient.applySessionToken(DocumentClient.java:3143)
        at com.microsoft.azure.documentdb.DocumentClient.doRead(DocumentClient.java:3051)
        at com.microsoft.azure.documentdb.DocumentClient.readDocument(DocumentClient.java:1041)
        at com.tomtom.lns.batch.dao.CosmosDBDao.getDocumentByBatchId(CosmosDBDao.java:358)

Our retrieve method:

private Document getDocumentByBatchId(final DocumentClient client, final BatchId batchId) {
    try {
      final RequestOptions requestOptions = new RequestOptions();
      requestOptions.setPartitionKey(new PartitionKey(batchId.getUuid().toString()));
      requestOptions.setConsistencyLevel(ConsistencyLevel.Strong);
      return client.readDocument(getBatchDocumentLink(batchId), requestOptions).getResource();
    } catch (DocumentClientException e) {
      if (e.getStatusCode() == HttpStatus.NOT_FOUND.value()) {
        throw new BatchNotFoundException(batchId);
      }
      throw new IllegalStateException("Cannot fetch Batch document: " + batchId, e);
    }
  }

And for clarity getBatchDocumentLink() method:

private static final String BATCH_DOCUMENT_LINK_TEMPLATE = "/dbs/BatchDB/colls/batches/docs/%s"
...
  private String getBatchDocumentLink(final BatchId batchId) {
    return String.format(BATCH_DOCUMENT_LINK_TEMPLATE, batchId.getUuid().toString());
  }

Our DocumentClient is created by:

  private DocumentClient createDocumentClient(final String url, final String masterKey,
      final ImmutableList<String> preferredLocations) {
    final ConnectionPolicy connectionPolicy = new ConnectionPolicy();
    connectionPolicy.setEnableEndpointDiscovery(true);
    connectionPolicy.setConnectionMode(ConnectionMode.DirectHttps);
    connectionPolicy.setMaxPoolSize(CONNECTION_POOL_SIZE);
    connectionPolicy.setPreferredLocations(preferredLocations);
    return new DocumentClient(url, masterKey, connectionPolicy, ConsistencyLevel.Session);
  }
@srinathnarayanan
Copy link
Contributor

Hi @mkozioro how often are you seeing this? Which version of the SDK are you using?

@mkozioro
Copy link
Author

Hi @srinathnarayanan
We are using SDK Version: 1.16.0. We're not getting that often. Less than 20 times, while running our app stress test. It just looks strange and we don't have source codes to check it.

We stopped to see that error after removing requestOptions.setConsistencyLevel(ConsistencyLevel.Strong);
line. I'm not sure if we shouldn't set that consistency level or there is a bug in SDKs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants