private Status insertBatch(String key, Map<String, ByteIterator> values) { HashMap<String, EntityProperty> properties = new HashMap<String, EntityProperty>(); for (Entry<String, ByteIterator> entry : values.entrySet()) { String fieldName = entry.getKey(); byte[] fieldVal = entry.getValue().toArray(); properties.put(fieldName, new EntityProperty(fieldVal)); } DynamicTableEntity entity = new DynamicTableEntity(partitionKey, key, properties); BATCH_OPERATION.insertOrReplace(entity); if (++curIdx == batchSize) { try { cloudTable.execute(BATCH_OPERATION); BATCH_OPERATION.clear(); curIdx = 0; } catch (Exception e) { return Status.ERROR; } } return Status.OK; }
private void deleteEntities(Iterator<TaskCheckpointEntity> entitiesToDelete) { TableBatchOperation batchOperation = new TableBatchOperation(); while (entitiesToDelete.hasNext()) { TaskCheckpointEntity entity = entitiesToDelete.next(); // Add to batch operation batchOperation.delete(entity); // Execute when batch reaches capacity or when this is the last item if (batchOperation.size() >= MAX_WRITE_BATCH_SIZE || !entitiesToDelete.hasNext()) { try { cloudTable.execute(batchOperation); } catch (StorageException e) { LOG.error("Executing batch failed for deleting checkpoints"); throw new AzureException(e); } batchOperation.clear(); } } } }
throw new AzureException(e); batchOperation.clear();