Commit a53f53e7 authored by chiaming2000's avatar chiaming2000
Browse files

Batch operation: fixed put command throws Exception if entry was not

found in store.  
parent 3c86e6cd
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -245,16 +245,9 @@ public class BatchOperationHandler {

        ByteString requestDbVersion = requestKeyValue.getDbVersion();

        ByteString storeDbVersion = null;

        ByteString key = requestKeyValue.getKey();

        @SuppressWarnings("unchecked")
        KVValue storeKv = (KVValue) store.get(key);

        if (storeKv != null) {
            storeDbVersion = storeKv.getVersion();
        }
        ByteString storeDbVersion = this.getDbVersion(key);

        logger.info("*********comparing version., storeV=" + storeDbVersion
                + "requestV=" + requestDbVersion);
@@ -264,6 +257,22 @@ public class BatchOperationHandler {
        logger.info("*********batch op version checked and passed ...");
    }

    @SuppressWarnings("unchecked")
    private ByteString getDbVersion(ByteString key) {

        KVValue storeKv = null;
        ByteString storeDbVersion = null;

        try {
            storeKv = (KVValue) store.get(key);
            storeDbVersion = storeKv.getVersion();
        } catch (Exception e) {
            ;
        }

        return storeDbVersion;
    }

    public synchronized boolean isClosed() {
        return this.isEndBatch;
    }
+5 −2
Original line number Diff line number Diff line
@@ -65,6 +65,9 @@ public class BatchOperationExample implements CallbackHandler<Entry> {

        client.putForced(bar);

        // delete foo if existed
        client.deleteForced("foo".getBytes("UTF8"));

        logger.info("*** starting batch operation ...");

        // start batch a new batch operation
@@ -74,9 +77,9 @@ public class BatchOperationExample implements CallbackHandler<Entry> {
        Entry foo = new Entry();
        foo.setKey("foo".getBytes("UTF8"));
        foo.setValue("foo".getBytes("UTF8"));
        foo.getEntryMetadata().setVersion("5678".getBytes("UTF8"));
        // foo.getEntryMetadata().setVersion("5678".getBytes("UTF8"));

        batch.putForcedAsync(foo, this);
        batch.putAsync(foo, "5678".getBytes("UTF8"), this);

        // delete bar
        DeleteCbHandler dhandler = new DeleteCbHandler();