weisong44 commented on a change in pull request #1031: SAMZA-2191: Batch 
support for table APIs
URL: https://github.com/apache/samza/pull/1031#discussion_r285363501
 
 

 ##########
 File path: 
samza-core/src/main/java/org/apache/samza/table/batching/AsyncBatchingTable.java
 ##########
 @@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.samza.table.batching;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ScheduledExecutorService;
+import org.apache.samza.SamzaException;
+import org.apache.samza.context.Context;
+import org.apache.samza.storage.kv.Entry;
+import org.apache.samza.table.AsyncReadWriteTable;
+import org.apache.samza.table.utils.TableMetricsUtil;
+
+
+/**
+ * A wrapper of a {@link AsyncReadWriteTable} that supports batch operations.
+ *
+ * This batching table does not guarantee any ordering of different operation 
types within the batch.
+ * For instance, query(Q) and update(u) operations arrives in the following 
sequences, Q1, U1, Q2, U2,
+ * it does not mean the the remote data store will receive the messages in the 
same order. Instead,
+ * the operations will be grouped by type and sent via micro batches. For this 
sequence, Q1 and Q2 will
+ * be grouped to micro batch B1; U1 and U2 will be grouped to micro batch B2, 
the implementation class
+ * can decide the order of the micro batches.
+ *
+ * Synchronized table operations (get/put/delete) should be used with caution 
for the batching feature.
+ * If the table is used by a single thread, there will be at most one 
operation in the batch, and the
+ * batch will be performed when the TTL of the batch window expires. Batching 
does not make sense in this scenario.
+ *
+ * Note: The batching feature will ignore the "args" parameter for each API.
+ *
+ * @param <K> The type of the key.
+ * @param <V> The type of the value.
+ */
+public class AsyncBatchingTable<K, V> implements AsyncReadWriteTable<K, V> {
+  private final AsyncReadWriteTable<K, V> table;
+  private final String tableId;
+  private final BatchProvider<K, V> batchProvider;
+  private final ScheduledExecutorService batchTimerExecutorService;
+  private BatchProcessor<K, V> batchProcessor;
+
+  /**
+   * @param tableId The id of the table.
+   * @param table The target table that serves the batch operations.
+   * @param batchProvider Batch provider to create a batch instance.
+   */
+  public AsyncBatchingTable(String tableId, AsyncReadWriteTable table, 
BatchProvider<K, V> batchProvider,
+      ScheduledExecutorService batchTimerExecutorService) {
+    Preconditions.checkNotNull(tableId);
+    Preconditions.checkNotNull(table);
+    Preconditions.checkNotNull(batchProvider);
+    Preconditions.checkNotNull(batchTimerExecutorService);
+
+    this.tableId = tableId;
+    this.table = table;
+    this.batchProvider = batchProvider;
+    this.batchTimerExecutorService = batchTimerExecutorService;
+  }
+
+  @Override
+  public CompletableFuture<V> getAsync(K key, Object... args) {
+    Preconditions.checkNotNull(key);
+
+    try {
+      return batchProcessor.processQueryOperation(new GetOperation<>(key));
 
 Review comment:
   Args need to be included in operation.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to