Commit 1b6ff10f authored by chiaming2000's avatar chiaming2000
Browse files

1. Java API: fixed typo in BatchAbortedException.

2. Simulator: support commands with same keys in a batch. Versioned
PUT/DELETE are validated against the store and among the batch commands
in sequence before batch is committed to the store.
parent db0b1b02
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ public class BatchAbortedException extends KineticException {
     * @return the failed command index number starting with 0 for the first
     *         command
     */
    public int getFiledOperationIndex() {
    public int getFailedOperationIndex() {
        return index;
    }

+26 −3
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@
package com.seagate.kinetic.simulator.internal;

import java.util.ArrayList;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

@@ -63,6 +65,9 @@ public class BatchOperationHandler {

    private BatchOperation<ByteString, KVValue> batch = null;

    //
    private Map<ByteString, ByteString> map = new ConcurrentHashMap<ByteString, ByteString>();

    // sequence list
    private ArrayList<Long> sequenceList = new ArrayList<Long>();

@@ -102,6 +107,9 @@ public class BatchOperationHandler {
            // clear seq list
            sequenceList.clear();

            // clear version map
            map.clear();

            // clear exception
            this.batchException = null;
        } catch (KVStoreException e) {
@@ -399,10 +407,13 @@ public class BatchOperationHandler {

        // check version if required
        if (requestKeyValue.getForce() == false) {
            checkVersion(requestKeyValue);
            checkVersion(km);
        }

        batch.delete(key);

        // delete entry from map.
        map.remove(key);
    }

    private void batchPut(KineticMessage km) throws KVStoreException,
@@ -426,7 +437,7 @@ public class BatchOperationHandler {

        // check version if required
        if (requestKeyValue.getForce() == false) {
            checkVersion(requestKeyValue);
            checkVersion(km);
        }

        // construct store KV
@@ -441,6 +452,9 @@ public class BatchOperationHandler {

        // batch put
        batch.put(key, data);

        // put to batch map for version comparison
        map.put(requestKeyValue.getKey(), requestKeyValue.getNewVersion());
    }

    private synchronized void commitBatch(RequestContext context) {
@@ -513,7 +527,9 @@ public class BatchOperationHandler {
        return s.size();
    }

    private void checkVersion(KeyValue requestKeyValue) throws KVStoreException {
    private void checkVersion(KineticMessage km) throws KVStoreException {

        KeyValue requestKeyValue = km.getCommand().getBody().getKeyValue();

        ByteString requestDbVersion = requestKeyValue.getDbVersion();

@@ -521,7 +537,14 @@ public class BatchOperationHandler {

        ByteString storeDbVersion = this.getDbVersion(key);

        // compare version with store
        compareVersion(storeDbVersion, requestDbVersion);

        // compare version with batch map
        ByteString mapVersion = this.map.get(key);
        if (mapVersion != null) {
            compareVersion(mapVersion, requestDbVersion);
        }
    }

    @SuppressWarnings("unchecked")
+6 −6
Original line number Diff line number Diff line
@@ -2598,8 +2598,8 @@ public class BatchOpAPITest extends IntegrationTestCase {
        } catch (BatchAbortedException e) {
            assertTrue(e.getResponseMessage().getCommand().getStatus()
                    .getCode().equals(StatusCode.INVALID_BATCH));
            System.out.println(e.getFiledOperationIndex());
            assertTrue(e.getFiledOperationIndex() == 0);
            System.out.println(e.getFailedOperationIndex());
            assertTrue(e.getFailedOperationIndex() == 0);

        } catch (KineticException e) {
            Assert.fail("received unexpected exception: " + e.getMessage());
@@ -2660,7 +2660,7 @@ public class BatchOpAPITest extends IntegrationTestCase {
        } catch (BatchAbortedException e) {
            assertTrue(e.getResponseMessage().getCommand().getStatus()
                    .getCode().equals(StatusCode.INVALID_BATCH));
            assertTrue(e.getFiledOperationIndex() == 0);
            assertTrue(e.getFailedOperationIndex() == 0);

        } catch (KineticException e) {
            Assert.fail("received unexpected exception: " + e.getMessage());
@@ -2694,7 +2694,7 @@ public class BatchOpAPITest extends IntegrationTestCase {
        } catch (BatchAbortedException e) {
            assertTrue(e.getResponseMessage().getCommand().getStatus()
                    .getCode().equals(StatusCode.INVALID_BATCH));
            assertTrue(e.getFiledOperationIndex() == 0);
            assertTrue(e.getFailedOperationIndex() == 0);

        } catch (KineticException e) {
            Assert.fail("received unexpected exception: " + e.getMessage());
@@ -2733,7 +2733,7 @@ public class BatchOpAPITest extends IntegrationTestCase {
        } catch (BatchAbortedException e) {
            assertTrue(e.getResponseMessage().getCommand().getStatus()
                    .getCode().equals(StatusCode.INVALID_BATCH));
            assertTrue(e.getFiledOperationIndex() == 0);
            assertTrue(e.getFailedOperationIndex() == 0);

        } catch (KineticException e) {
            Assert.fail("received unexpected exception: " + e.getMessage());
@@ -2783,7 +2783,7 @@ public class BatchOpAPITest extends IntegrationTestCase {
        } catch (BatchAbortedException e) {
            assertTrue(e.getResponseMessage().getCommand().getStatus()
                    .getCode().equals(StatusCode.INVALID_BATCH));
            assertTrue(e.getFiledOperationIndex() == 0);
            assertTrue(e.getFailedOperationIndex() == 0);

        } catch (KineticException e) {
            Assert.fail("received unexpected exception: " + e.getMessage());
+2 −2
Original line number Diff line number Diff line
@@ -21,10 +21,10 @@ import java.io.UnsupportedEncodingException;
import java.util.logging.Level;
import java.util.logging.Logger;

import kinetic.client.BatchAbortedException;
import kinetic.client.BatchOperation;
import kinetic.client.ClientConfiguration;
import kinetic.client.Entry;
import kinetic.client.BatchAbortedException;
import kinetic.client.KineticClient;
import kinetic.client.KineticClientFactory;
import kinetic.client.KineticException;
@@ -95,7 +95,7 @@ public class BatchOperationFailedExample {
                // get status
                Status status = e.getResponseMessage().getCommand().getStatus();

                int index = e.getFiledOperationIndex();
                int index = e.getFailedOperationIndex();

                logger.info("received expected exception: " + status.getCode()
                        + ":" + status.getStatusMessage() + ", index=" + index);