Package voldemort.client.protocol.admin

Examples of voldemort.client.protocol.admin.QueryKeyResult


                iterator = adminClient.streamingOps.queryKeys(queryNodeId,
                                                              storeName,
                                                              Arrays.asList(key).iterator());
                final StringWriter stringWriter = new StringWriter();

                QueryKeyResult queryKeyResult = iterator.next();

                if(!printedKey) {
                    // de-serialize and write key
                    byte[] keyBytes = queryKeyResult.getKey().get();
                    Object keyObject = keySerializer.toObject((null == keyCompressionStrategy) ? keyBytes
                                                                                              : keyCompressionStrategy.inflate(keyBytes));

                    writeVoldKeyOrValueInternal(keyBytes,
                                                keySerializer,
                                                keyCompressionStrategy,
                                                "KEY",
                                                out);
                    printedKey = true;
                }

                // iterate through, de-serialize and write values
                if(queryKeyResult.hasValues() && queryKeyResult.getValues().size() > 0) {

                    int elementId = -1;
                    for(int i = 0; i < nodeValues.size(); i++) {
                        if(Objects.equal(nodeValues.get(i).getKey(), queryKeyResult.getValues())) {
                            elementId = i;
                            break;
                        }
                    }

                    if(elementId == -1) {
                        ArrayList<Integer> nodes = new ArrayList<Integer>();
                        nodes.add(queryNodeId);
                        nodeValues.add(new AbstractMap.SimpleEntry<List<Versioned<byte[]>>, List<Integer>>(queryKeyResult.getValues(),
                                                                                                           nodes));
                    } else {
                        nodeValues.get(elementId).getValue().add(queryNodeId);
                    }

                    out.write(String.format("\nQueried node %d on store %s\n",
                                            queryNodeId,
                                            storeName));

                    int versionCount = 0;

                    if(queryKeyResult.getValues().size() > 1) {
                        out.write("VALUE " + versionCount + "\n");
                    }

                    for(Versioned<byte[]> versioned: queryKeyResult.getValues()) {

                        // write version
                        VectorClock version = (VectorClock) versioned.getVersion();
                        out.write("VECTOR_CLOCK_BYTE: " + ByteUtils.toHexString(version.toBytes())
                                  + "\n");
                        out.write("VECTOR_CLOCK_TEXT: " + version.toString() + '['
                                  + new Date(version.getTimestamp()).toString() + "]\n");

                        // write value
                        byte[] valueBytes = versioned.getValue();
                        writeVoldKeyOrValueInternal(valueBytes,
                                                    valueSerializer,
                                                    valueCompressionStrategy,
                                                    "VALUE",
                                                    out);
                        versionCount++;
                    }
                } // If a node does not host a key, it returns invalidmetdata
                  // exception.
                else if(queryKeyResult.hasException()) {
                    boolean isInvalidMetadataException = queryKeyResult.getException() instanceof InvalidMetadataException;

                    // Print the exception if not InvalidMetadataException or
                    // you are querying only a single node.
                    if(!isInvalidMetadataException || queryingNodes.size() == 1) {
                        out.write(String.format("\nNode %d on store %s returned exception\n",
                                                queryNodeId,
                                                storeName));
                        out.write(queryKeyResult.getException().toString());
                        out.write("\n====================================\n");
                    }
                } else {
                    if(queryingNodes.size() == 1) {
                        out.write(String.format("\nNode %d on store %s returned NULL\n",
View Full Code Here


        byte[] bKey = TestUtils.randomBytes(10);
        String hexKey = ByteUtils.toHexString(bKey);
        ByteArray baKey = new ByteArray(bKey);

        BadKey badKey;
        QueryKeyResult queryKeyResult;
        if(!orphan) {
            badKey = new BadKey(hexKey, hexKey + "\n");
            queryKeyResult = null;
        } else {
            StringBuilder orphanInput = new StringBuilder();
            orphanInput.append(hexKey + "," + "1\n");
            List<Versioned<byte[]>> values = new ArrayList<Versioned<byte[]>>(0);
            int arbitraryNodeId = 2;
            Versioned<byte[]> versioned = TestUtils.getVersioned(TestUtils.randomBytes(25),
                                                                 arbitraryNodeId);
            orphanInput.append(ByteUtils.toHexString(versioned.getValue()));
            orphanInput.append("," + versioned.toString() + "\n");
            values.add(versioned);

            badKey = new BadKey(hexKey, orphanInput.toString());
            queryKeyResult = new QueryKeyResult(baKey, values);
        }

        Versioned<byte[]> value = TestUtils.getVersioned(TestUtils.randomBytes(25), 0);

        String url = ConsistencyFixTest.setUpCluster();
View Full Code Here

        ArrayList<ByteArray> belongToServer0ButOutsideBothKeys = new ArrayList<ByteArray>(belongToServer0ButOutsideBoth.keySet());
        ArrayList<ByteArray> notBelongToServer0AndOutsideBothKeys = new ArrayList<ByteArray>(notBelongToServer0AndOutsideBoth.keySet());

        List<ByteArray> queryKeys;
        Iterator<QueryKeyResult> results;
        QueryKeyResult entry;
        // test one key on store 0
        queryKeys = new ArrayList<ByteArray>();
        queryKeys.add(belongToAndInsideServer0Keys.get(0));
        results = getAdminClient().streamingOps.queryKeys(0, testStoreName, queryKeys.iterator());
        assertTrue("Results should not be empty", results.hasNext());
        entry = results.next();
        assertEquals(queryKeys.get(0), entry.getKey());
        assertNull("There should not be exception in response", entry.getException());
        assertEquals("There should be only 1 value in versioned list", 1, entry.getValues().size());
        assertEquals("Two byte[] should be equal",
                     0,
                     ByteUtils.compare(belongToAndInsideServer0.get(queryKeys.get(0)),
                                       entry.getValues().get(0).getValue()));
        assertFalse("There should be only one result", results.hasNext());

        // test one key belongs to but not exists in server 0
        queryKeys = new ArrayList<ByteArray>();
        queryKeys.add(belongToServer0ButOutsideBothKeys.get(0));
        results = getAdminClient().streamingOps.queryKeys(0, testStoreName, queryKeys.iterator());
        assertTrue("Results should not be empty", results.hasNext());
        entry = results.next();
        assertFalse("There should not be more results", results.hasNext());
        assertEquals("Not the right key", queryKeys.get(0), entry.getKey());
        assertFalse("There should not be exception", entry.hasException());
        assertTrue("There should be values", entry.hasValues());
        assertNotNull("Response should be non-null", entry.getValues());
        assertEquals("Value should be empty list", 0, entry.getValues().size());
        assertNull("There should not be exception", entry.getException());

        // test one key not exist and does not belong to server 0
        queryKeys = new ArrayList<ByteArray>();
        queryKeys.add(notBelongToServer0AndOutsideBothKeys.get(0));
        results = getAdminClient().streamingOps.queryKeys(0, testStoreName, queryKeys.iterator());
        assertTrue("Results should not be empty", results.hasNext());
        entry = results.next();
        assertFalse("There should not be more results", results.hasNext());
        assertEquals("Not the right key", queryKeys.get(0), entry.getKey());
        assertTrue("There should be exception", entry.hasException());
        assertFalse("There should not be values", entry.hasValues());
        assertNull("Value should be null", entry.getValues());
        assertTrue("There should be InvalidMetadataException exception",
                   entry.getException() instanceof InvalidMetadataException);

        // test one key that exists on server 0 but does not belong to server 0
        queryKeys = new ArrayList<ByteArray>();
        queryKeys.add(notBelongServer0ButInsideServer0Keys.get(0));
        results = getAdminClient().streamingOps.queryKeys(0, testStoreName, queryKeys.iterator());
        assertTrue("Results should not be empty", results.hasNext());
        entry = results.next();
        assertFalse("There should not be more results", results.hasNext());
        assertEquals("Not the right key", queryKeys.get(0), entry.getKey());
        assertTrue("There should be exception", entry.hasException());
        assertFalse("There should not be values", entry.hasValues());
        assertNull("Value should be null", entry.getValues());
        assertTrue("There should be InvalidMetadataException exception",
                   entry.getException() instanceof InvalidMetadataException);

        // test one key deleted
        store0.delete(belongToAndInsideServer0Keys.get(4), null);
        queryKeys = new ArrayList<ByteArray>();
        queryKeys.add(belongToAndInsideServer0Keys.get(4));
        results = getAdminClient().streamingOps.queryKeys(0, testStoreName, queryKeys.iterator());
        assertTrue("Results should not be empty", results.hasNext());
        entry = results.next();
        assertFalse("There should not be more results", results.hasNext());
        assertFalse("There should not be exception", entry.hasException());
        assertTrue("There should be values", entry.hasValues());
        assertEquals("Not the right key", queryKeys.get(0), entry.getKey());
        assertEquals("Value should be empty list", 0, entry.getValues().size());

        // test empty request
        queryKeys = new ArrayList<ByteArray>();
        results = getAdminClient().streamingOps.queryKeys(0, testStoreName, queryKeys.iterator());
        assertFalse("Results should be empty", results.hasNext());

        // test null key
        queryKeys = new ArrayList<ByteArray>();
        queryKeys.add(null);
        assertEquals(1, queryKeys.size());
        results = getAdminClient().streamingOps.queryKeys(0, testStoreName, queryKeys.iterator());
        assertTrue("Results should not be empty", results.hasNext());
        entry = results.next();
        assertFalse("There should not be more results", results.hasNext());
        assertTrue("There should be exception", entry.hasException());
        assertFalse("There should not be values", entry.hasValues());
        assertNull("Value should be null", entry.getValues());
        assertTrue("There should be IllegalArgumentException exception",
                   entry.getException() instanceof IllegalArgumentException);

        // test multiple keys (3) on store 1
        queryKeys = new ArrayList<ByteArray>();
        queryKeys.add(belongToAndInsideServer1Keys.get(0));
        queryKeys.add(belongToAndInsideServer1Keys.get(1));
        queryKeys.add(belongToAndInsideServer1Keys.get(2));
        results = getAdminClient().streamingOps.queryKeys(1, testStoreName, queryKeys.iterator());
        assertTrue("Results should not be empty", results.hasNext());
        Map<ByteArray, List<Versioned<byte[]>>> entries = new HashMap<ByteArray, List<Versioned<byte[]>>>();
        int resultCount = 0;
        while(results.hasNext()) {
            resultCount++;
            entry = results.next();
            assertNull("There should not be exception in response", entry.getException());
            assertNotNull("Value should not be null for Key: ", entry.getValues());
            entries.put(entry.getKey(), entry.getValues());
        }
        assertEquals("There should 3 and only 3 results", 3, resultCount);
        for(ByteArray key: queryKeys) {
            // this loop and the count ensure one-to-one mapping
            assertNotNull("This key should exist in the results: " + key, entries.get(key));
            assertEquals("Two byte[] should be equal for key: " + key,
                         0,
                         ByteUtils.compare(belongToAndInsideServer1.get(key),
                                           entries.get(key).get(0).getValue()));
        }

        // test multiple keys, mixed situation
        // key 0: Exists and belongs to
        // key 1: Exists but does not belong to
        // key 2: Does not exist but belongs to
        // key 3: Does not belong and not exist
        // key 4: Same situation with key0
        // key 5: Deleted
        // key 6: Same situation with key2
        store0.delete(belongToAndInsideServer0Keys.get(5), null);
        queryKeys = new ArrayList<ByteArray>();
        queryKeys.add(belongToAndInsideServer0Keys.get(2));
        queryKeys.add(notBelongServer0ButInsideServer0Keys.get(1));
        queryKeys.add(belongToServer0ButOutsideBothKeys.get(1));
        queryKeys.add(notBelongToServer0AndOutsideBothKeys.get(1));
        queryKeys.add(belongToAndInsideServer0Keys.get(3));
        queryKeys.add(belongToAndInsideServer0Keys.get(5));
        queryKeys.add(notBelongServer0ButInsideServer0Keys.get(2));
        results = getAdminClient().streamingOps.queryKeys(0, testStoreName, queryKeys.iterator());
        // key 0
        entry = results.next();
        assertEquals(0, ByteUtils.compare(queryKeys.get(0).get(), entry.getKey().get()));
        assertEquals(0, ByteUtils.compare(belongToAndInsideServer0.get(queryKeys.get(0)),
                                          entry.getValues().get(0).getValue()));
        assertNull(entry.getException());
        // key 1
        entry = results.next();
        assertEquals(0, ByteUtils.compare(queryKeys.get(1).get(), entry.getKey().get()));
        assertTrue("There should be InvalidMetadataException exception",
                   entry.getException() instanceof InvalidMetadataException);
        // key 2
        entry = results.next();
        assertEquals(0, ByteUtils.compare(queryKeys.get(2).get(), entry.getKey().get()));
        assertEquals(0, entry.getValues().size());
        assertNull(entry.getException());
        // key 3
        entry = results.next();
        assertEquals(0, ByteUtils.compare(queryKeys.get(3).get(), entry.getKey().get()));
        assertTrue("There should be InvalidMetadataException exception",
                   entry.getException() instanceof InvalidMetadataException);
        // key 4
        entry = results.next();
        assertEquals(0, ByteUtils.compare(queryKeys.get(4).get(), entry.getKey().get()));
        assertEquals(0, ByteUtils.compare(belongToAndInsideServer0.get(queryKeys.get(4)),
                                          entry.getValues().get(0).getValue()));
        assertNull(entry.getException());
        // key 5
        entry = results.next();
        assertEquals(0, ByteUtils.compare(queryKeys.get(5).get(), entry.getKey().get()));
        assertEquals(0, entry.getValues().size());
        assertNull(entry.getException());
        // key 6
        entry = results.next();
        assertEquals(0, ByteUtils.compare(queryKeys.get(6).get(), entry.getKey().get()));
        assertTrue("There should be InvalidMetadataException exception",
                   entry.getException() instanceof InvalidMetadataException);
        // no more keys
        assertFalse(results.hasNext());
    }
View Full Code Here

        // do the positive tests
        Iterator<QueryKeyResult> positiveTestResultsItr = admin.streamingOps.queryKeys(serverId,
                                                                                       store,
                                                                                       keyList.iterator());
        while(positiveTestResultsItr.hasNext()) {
            QueryKeyResult item = positiveTestResultsItr.next();
            ByteArray key = item.getKey();
            List<Versioned<byte[]>> vals = item.getValues();
            Exception e = item.getException();

            assertEquals("Error fetching key " + key, null, e);
            assertEquals("Value not found for key " + key, true, vals != null & vals.size() != 0);

        }
View Full Code Here

        // do the positive tests
        Iterator<QueryKeyResult> positiveTestResultsItr = admin.streamingOps.queryKeys(serverId,
                                                                                       store,
                                                                                       keyList.iterator());
        while(positiveTestResultsItr.hasNext()) {
            QueryKeyResult item = positiveTestResultsItr.next();
            ByteArray key = item.getKey();
            List<Versioned<byte[]>> vals = item.getValues();
            Exception e = item.getException();

            assertEquals("Error fetching key " + key, null, e);
            assertEquals("Value not found for key " + key, true, vals != null & vals.size() != 0);

            String keyStr = ByteUtils.getString(key.get(), "UTF-8");
View Full Code Here

                                           List<ByteArray> keyList) {
        Iterator<QueryKeyResult> negativeTestResultsItr = admin.streamingOps.queryKeys(serverId,
                                                                                       store,
                                                                                       keyList.iterator());
        while(negativeTestResultsItr.hasNext()) {
            QueryKeyResult item = negativeTestResultsItr.next();
            ByteArray key = item.getKey();
            List<Versioned<byte[]>> vals = item.getValues();
            Exception e = item.getException();

            assertEquals("Error fetching key " + key, null, e);
            assertEquals("Value " + vals + "found for key " + key,
                         true,
                         vals == null || vals.size() == 0);
View Full Code Here

            try {
                values = this.adminClient.storeOps.getNodeKey(this.storeInstance.getStoreDefinition()
                                                                                .getName(),
                                                              nodeId,
                                                              key);
                nodeIdToKeyValues.put(nodeId, new QueryKeyResult(key, values));
            } catch(VoldemortException ve) {
                nodeIdToKeyValues.put(nodeId, new QueryKeyResult(key, ve));
            }
        }

        return nodeIdToKeyValues;
    }
View Full Code Here

                                                        final String keyInHexFormat,
                                                        final Map<Integer, QueryKeyResult> nodeIdToKeyValues) {
        List<NodeValue<ByteArray, byte[]>> nodeValues = new ArrayList<NodeValue<ByteArray, byte[]>>();
        boolean exceptionsEncountered = false;
        for(int nodeId: nodeIdList) {
            QueryKeyResult keyValue;
            if(nodeIdToKeyValues.containsKey(nodeId)) {
                keyValue = nodeIdToKeyValues.get(nodeId);

                if(keyValue.hasException()) {
                    logger.debug("Exception encountered while fetching key " + keyInHexFormat
                                 + " from node with nodeId " + nodeId + " : "
                                 + keyValue.getException().getMessage());
                    exceptionsEncountered = true;
                } else {
                    if(keyValue.getValues().isEmpty()) {
                        Versioned<byte[]> versioned = new Versioned<byte[]>(null);
                        nodeValues.add(new NodeValue<ByteArray, byte[]>(nodeId,
                                                                        keyValue.getKey(),
                                                                        versioned));

                    } else {
                        for(Versioned<byte[]> value: keyValue.getValues()) {
                            nodeValues.add(new NodeValue<ByteArray, byte[]>(nodeId,
                                                                            keyValue.getKey(),
                                                                            value));
                        }
                    }
                }
            } else {
View Full Code Here

                    iterator = adminClient.streamingOps.queryKeys(queryNodeId,
                                                                  storeName,
                                                                  Arrays.asList(key).iterator());
                    final StringWriter stringWriter = new StringWriter();

                    QueryKeyResult queryKeyResult = iterator.next();

                    if(!printedKey) {
                        // de-serialize and write key
                        byte[] keyBytes = queryKeyResult.getKey().get();
                        Object keyObject = keySerializer.toObject((null == keyCompressionStrategy) ? keyBytes
                                                                                                  : keyCompressionStrategy.inflate(keyBytes));

                        writeVoldKeyOrValueInternal(keyBytes,
                                                    keySerializer,
                                                    keyCompressionStrategy,
                                                    "KEY",
                                                    out);
                        printedKey = true;
                    }

                    // iterate through, de-serialize and write values
                    if(queryKeyResult.hasValues() && queryKeyResult.getValues().size() > 0) {

                        int elementId = -1;
                        for(int i = 0; i < nodeValues.size(); i++) {
                            if(Objects.equal(nodeValues.get(i).getKey(), queryKeyResult.getValues())) {
                                elementId = i;
                                break;
                            }
                        }

                        if(elementId == -1) {
                            ArrayList<Integer> nodes = new ArrayList<Integer>();
                            nodes.add(queryNodeId);
                            nodeValues.add(new AbstractMap.SimpleEntry<List<Versioned<byte[]>>, List<Integer>>(queryKeyResult.getValues(),
                                                                                                               nodes));
                        } else {
                            nodeValues.get(elementId).getValue().add(queryNodeId);
                        }

                        out.write(String.format("\nQueried node %d on store %s\n",
                                                queryNodeId,
                                                storeName));

                        int versionCount = 0;

                        if(queryKeyResult.getValues().size() > 1) {
                            out.write("VALUE " + versionCount + "\n");
                        }

                        for(Versioned<byte[]> versioned: queryKeyResult.getValues()) {

                            // write version
                            VectorClock version = (VectorClock) versioned.getVersion();
                            out.write("VECTOR_CLOCK_BYTE: "
                                      + ByteUtils.toHexString(version.toBytes()) + "\n");
                            out.write("VECTOR_CLOCK_TEXT: " + version.toString() + '['
                                      + new Date(version.getTimestamp()).toString() + "]\n");

                            // write value
                            byte[] valueBytes = versioned.getValue();
                            writeVoldKeyOrValueInternal(valueBytes,
                                                        valueSerializer,
                                                        valueCompressionStrategy,
                                                        "VALUE",
                                                        out);
                            versionCount++;
                        }
                    } // If a node does not host a key, it returns
                      // invalidmetdata
                      // exception.
                    else if(queryKeyResult.hasException()) {
                        boolean isInvalidMetadataException = queryKeyResult.getException() instanceof InvalidMetadataException;

                        // Print the exception if not InvalidMetadataException
                        // or
                        // you are querying only a single node.
                        if(!isInvalidMetadataException || queryingNodes.size() == 1) {
                            out.write(String.format("\nNode %d on store %s returned exception\n",
                                                    queryNodeId,
                                                    storeName));
                            out.write(queryKeyResult.getException().toString());
                            out.write("\n====================================\n");
                        }
                    } else {
                        if(queryingNodes.size() == 1) {
                            out.write(String.format("\nNode %d on store %s returned NULL\n",
View Full Code Here

                    ByteArray keyToResolve = keyItr.next();
                    Map<Integer, QueryKeyResult> valuesMap = doReads(nodeList, keyToResolve.get());
                    List<Versioned<byte[]>> values = new ArrayList<Versioned<byte[]>>(valuesMap.size());
                    for(Map.Entry<Integer, QueryKeyResult> entry: valuesMap.entrySet()) {
                        int nodeId = entry.getKey();
                        QueryKeyResult result = entry.getValue();

                        if(result.hasException()) {
                            logger.error(workName + "key fetch failed for key "
                                                 + ByteUtils.toHexString(keyToResolve.get())
                                                 + " on node " + nodeId,
                                         result.getException());
                            break;
                        }
                        values.addAll(result.getValues());
                    }

                    List<Versioned<byte[]>> resolvedVersions = resolver.resolveConflicts(values);
                    // after timestamp based resolving there should be only one
                    // version. Insert that to the destination cluster with
View Full Code Here

TOP

Related Classes of voldemort.client.protocol.admin.QueryKeyResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.