when the table quota is insufficient, some operations that allow batch operations are executed
BatchResult partialAllowedBatch(BatchRequest request)
Function
General batch request, when the table quota is insufficient, it will all be rejected; while partialAllowedBatch allows part of the record to be executed within the scope of the quota satisfied, through the return value the user is informed which records are executed successfully, which records are not executed, if the current quota does not meet even 1 record execution, it will throw a THROUGHPUT_EXCEED exception; the user needs to check the return value and send a request for a record that is not executed in a loop until all records are successfully executed.
Method parameters
request : BatchRequest : required
BatchRequest includes a list of available PutRequest, RemoveRequest, GetRequest and IncrementRequest
1.items : List< BatchRequestItem > : required
BatchRequestItem includes BatchOp and Request
The enumeration type BatchOp (PUT, GET, REMOVE, INCREMENT) specifies the operation type of the request,
Correspondingly, use putRequest, getRequest, removeRequest and incrementRequest to construct the Request parameter
Method return value
batchResult : BatchResult
BatchResult includes a list with BatchResultItems that represents the execution result of each request of the batch
items : List< BatchResultItem >
Returns the result of each sub-operation, isSuccess==true indicates that execution has been performed and isSuccess==false indicates no execution
Limitation
Each sub-operation must be the same table
put, remove request does not support conditionals
The range of sub-operands for a batch operation is [ 1, 100 ]
Example
The following sample code
List<BatchRequestItem> batch = new ArrayList<BatchRequestItem>();
for (int i = 11; i < 20; i++) {
BatchRequestItem item = new BatchRequestItem().setAction(BatchOp.PUT);
Map<String, Datum> record = new HashMap<String, Datum>();
record.put("cityId", DatumUtil.toDatum(cities[i]));
putRequest.putToRecord("timestamp", DatumUtil.toDatum(now.getTime()));
putRequest.putToRecord("score", DatumUtil.toDatum((double) new Random().nextInt(100)));
putRequest.putToRecord("pm25", DatumUtil.toDatum((long) (new Random().nextInt(500))));
item.setRequest(Request.putRequest(new PutRequest().setTableName(tableName).setRecord(record)));
batch.add(item);
}
while (true) {
BatchResult br = tableClient.partialAllowedBatch(new BatchRequest().setItems(batch));
List<BatchRequestItem> request = new ArrayList<BatchRequestItem>();
for (int i = 0; i < br.getItems().size(); i++) {
//At current only quota exceeded will get isSuccess() == false
if (!br.getItems().get(i).isSuccess()) {
request.add(batch.get(i));
}
}
if (request.isEmpty()) {
break;
}
Thread.sleep(100); // wait a while to retry.
batch = request;
}