Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

NullPointerException in bulk delete operation using Azure Cosmos DB BulkExecutor and Java

I am trying to use bulk delete operation that comes with Java BulkExecutor library. Following the sample provided: https://github.com/Azure/azure-cosmosdb-bulkexecutor-java-getting-started/blob/master/samples/bulkexecutor-sample/src/main/java/com/microsoft/azure/cosmosdb/bulkexecutor/bulkdelete/BulkDeleter.java

I am using documentdb-bulkexecutor v2.10.0 and Azure Java SDK v2 (azure-documentdb 2.6.1)

public int deleteAllFromInstituteInBulkCosmos(List<org.apache.commons.lang3.tuple.Pair<String, String>> pkIdPairsToDelete) throws Exception {
        
          // Set client's retry options high for initialization
        documentClient.getConnectionPolicy().getRetryOptions().setMaxRetryWaitTimeInSeconds(120);
        documentClient.getConnectionPolicy().getRetryOptions().setMaxRetryAttemptsOnThrottledRequests(100);
        
        DocumentCollection collection =  documentClient.readCollection(this.collectionLink, null).getResource();
        
        //  Specify the maximum throughput (out of entire collection's throughput) that you wish the bulk import API to consume here
        int offerThroughput = AzureUtils.getOfferThroughput(documentClient, collection);

        Builder bulkExecutorBuilder = DocumentBulkExecutor.builder().from(documentClient, this.cosmosDatabaseId,
                this.cosmosCollectionId, collection.getPartitionKey(), offerThroughput);
        
        int numberofDocsDeleted=0;
        // Instantiate bulk executor
        try (DocumentBulkExecutor bulkExecutor = bulkExecutorBuilder.build()) {

BulkExecutor SDK is giving NullPointerException while initializing DocumentBulkExecutor.

DocumentBulkExecutor bulkExecutor = bulkExecutorBuilder.build()

I debugged further and found out NPE is coming from com.microsoft.azure.documentdb.internal.routing.Range class when it is comparing two partition key ranges.

public static class MinComparator<T extends Comparable<T>> implements Comparator<Range<T>> {
        @Override
        public int compare(Range<T> range1, Range<T> range2) {
            int result = range1.getMin().compareTo(range2.getMin());
            if (result != 0 || range1.isMinInclusive() == range2.isMinInclusive()) {
                return result;
            }

            return range1.isMinInclusive() ? -1 : 1;
        }
    }

... as range2.getMin() is null.

Below is the stack trace:

Caused by: java.lang.NullPointerException: null
    at java.lang.String.compareTo(String.java:1155)
    at java.lang.String.compareTo(String.java:111)
    at com.microsoft.azure.documentdb.internal.routing.Range$MinComparator.compare(Range.java:162)
    at com.microsoft.azure.documentdb.internal.routing.Range$MinComparator.compare(Range.java:159)
    at java.util.Collections.indexedBinarySearch(Collections.java:334)
    at java.util.Collections.binarySearch(Collections.java:322)
    at com.microsoft.azure.documentdb.internal.routing.InMemoryCollectionRoutingMap.getOverlappingRanges(InMemoryCollectionRoutingMap.java:254)
    at com.microsoft.azure.documentdb.internal.routing.InMemoryCollectionRoutingMap.getOverlappingRanges(InMemoryCollectionRoutingMap.java:242)
    at com.microsoft.azure.documentdb.bulkexecutor.DocumentBulkExecutor.initialize(DocumentBulkExecutor.java:441)
    at com.microsoft.azure.documentdb.bulkexecutor.DocumentBulkExecutor.safeInit(DocumentBulkExecutor.java:368)
    at com.microsoft.azure.documentdb.bulkexecutor.DocumentBulkExecutor.access$400(DocumentBulkExecutor.java:83)
    at com.microsoft.azure.documentdb.bulkexecutor.DocumentBulkExecutor$Builder.build(DocumentBulkExecutor.java:184)
    at be.landc.datastore.azure.AzureService.deleteAllFromInstituteInBulkCosmos(AzureService.java:529)
    at be.landc.datastore.azure.AzureService.deleteAllFromInstituteInBulk(AzureService.java:497)
    ... 6 common frames omitted

Thanks for any help or suggestions .

question from:https://stackoverflow.com/questions/65897534/nullpointerexception-in-bulk-delete-operation-using-azure-cosmos-db-bulkexecutor

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...