Search in sources :

Example 6 with PutException

use of com.ms.silverking.cloud.dht.client.PutException in project SilverKing by Morgan-Stanley.

the class GroupingSilverkingDB method insert.

@Override
public int insert(String table, String key, HashMap<String, ByteIterator> values) {
    try {
        // }
        if (System.currentTimeMillis() == 0) {
            syncNSP.put(key, values);
        }
        /**/
        {
            AsyncPut asyncPut;
            // System.out.println("Waiting for: "+ key);
            asyncPut = asyncNSP.put(key, values);
            try {
                asyncPut.waitForCompletion(30, TimeUnit.SECONDS);
                if (asyncPut.getState() == OperationState.INCOMPLETE) {
                    System.out.println("Incomplete: " + key);
                    System.out.flush();
                    System.exit(-1);
                }
            } catch (OperationException e) {
                PutException pe;
                pe = (PutException) e;
                if (pe.getFailureCause(key) == FailureCause.INVALID_VERSION) {
                    System.out.println("Ignoring INVALID_VERSION");
                    System.err.println("Ignoring INVALID_VERSION");
                    return 1;
                } else {
                    throw new RuntimeException(pe);
                }
            }
        }
        // System.out.println("Done waiting for: "+ key);
        return 0;
    } catch (PutException pe) {
        System.out.println("Key failed: " + key);
        return 1;
    }
}
Also used : PutException(com.ms.silverking.cloud.dht.client.PutException) AsyncPut(com.ms.silverking.cloud.dht.client.AsyncPut) OperationException(com.ms.silverking.cloud.dht.client.OperationException)

Example 7 with PutException

use of com.ms.silverking.cloud.dht.client.PutException in project SilverKing by Morgan-Stanley.

the class SilverKingClient method doInvalidation.

private void doInvalidation(String[] args) throws OperationException, IOException {
    Set<String> set;
    ImmutableSet.Builder<String> builder;
    builder = ImmutableSet.builder();
    for (int i = 0; i < args.length; i++) {
        builder.add(translateKey(args[i]));
    }
    set = builder.build();
    opMessage("Invalidating");
    sw.reset();
    try {
        for (int i = 0; i < reps; i++) {
            syncNSP.invalidate(set);
        }
    } catch (PutException pe) {
        out.println(pe.getDetailedFailureMessage());
        throw pe;
    }
    sw.stop();
}
Also used : PutException(com.ms.silverking.cloud.dht.client.PutException) ImmutableSet(com.google.common.collect.ImmutableSet) VersionConstraint(com.ms.silverking.cloud.dht.VersionConstraint)

Example 8 with PutException

use of com.ms.silverking.cloud.dht.client.PutException in project SilverKing by Morgan-Stanley.

the class AsyncPingMultiPong method clientIteration.

public void clientIteration(String pingKey, String pongKeyBase, long version) throws OperationException {
    Set<String> pongKeys;
    AsyncRetrieval<String, byte[]> asyncRetrieval;
    pongKeys = new HashSet<>(numServers);
    for (int i = 0; i < numServers; i++) {
        for (int j = 0; j < threadsPerServer; j++) {
            pongKeys.add(pongKeyBase + "." + i + "." + j);
        }
    }
    if (verbose) {
        System.out.println("Put: " + pingKey);
    }
    if (delayMS != 0) {
        if (verbose) {
            System.out.print("Sleeping...");
        }
        ThreadUtil.sleep(delayMS);
        if (verbose) {
            System.out.println("Awake.");
        }
    }
    try {
        AsyncPut<String> put;
        put = asyncNSP.put(pingKey, pingKey.getBytes(), defaultPutOptions.version(version));
        put.waitForCompletion();
    } catch (PutException pe) {
        System.out.println("ignoring put exception");
    }
    if (verbose) {
        System.out.println("WaitFor: " + pongKeyBase);
    }
    asyncRetrieval = asyncNSP.waitFor(pongKeys, asyncNSP.getOptions().getDefaultWaitOptions().versionConstraint(VersionConstraint.exactMatch(version)));
    while (asyncRetrieval.getState() == OperationState.INCOMPLETE) {
        asyncRetrieval.waitForCompletion(checkIntervalMS, TimeUnit.MILLISECONDS);
        if (asyncRetrieval.getState() == OperationState.INCOMPLETE) {
            Set<String> incompleteKeys;
            incompleteKeys = asyncRetrieval.getIncompleteKeys();
            System.out.println("IncompleteKeys: " + incompleteKeys.size());
            for (String key : incompleteKeys) {
                System.out.println(key);
            }
            System.out.println();
        }
    }
    if (verbose) {
        System.out.println("Received: " + pongKeyBase);
    }
}
Also used : PutException(com.ms.silverking.cloud.dht.client.PutException) VersionConstraint(com.ms.silverking.cloud.dht.VersionConstraint)

Example 9 with PutException

use of com.ms.silverking.cloud.dht.client.PutException in project SilverKing by Morgan-Stanley.

the class NamespaceOptionsClient method storeNamespaceProperties.

public void storeNamespaceProperties(long namespace, NamespaceProperties nsProperties) throws NamespaceCreationException {
    boolean retry;
    retry = false;
    do {
        NamespaceProperties existingProperties;
        try {
            existingProperties = getNamespaceProperties(namespace, seTimeoutController.getMaxRelativeTimeoutMillis(null));
        } catch (TimeoutException te) {
            Log.warning("Failed to store namespace due to timeout " + String.format("%x", namespace));
            throw new NamespaceCreationException(Long.toHexString(namespace), te);
        } catch (RetrievalException re) {
            Log.warning(re.getDetailedFailureMessage());
            throw new NamespaceCreationException("RetrievalException during first property check", re);
        }
        if (existingProperties != null) {
            if (!existingProperties.equals(nsProperties)) {
                Log.warning("existingProperties", existingProperties);
                Log.warning("nsProperties", nsProperties);
                throw new NamespaceCreationException("Namespace already created with incompatible properties");
            } else {
            // Already created with the same options. No further action required.
            }
        } else {
            try {
                if (debug) {
                    System.out.printf("storeNamespaceProperties(%x, %s)\n", namespace, nsProperties);
                }
                syncNSP.put(getOptionsKey(namespace), nsProperties.toString());
                if (debug) {
                    System.out.println("Done storeNamespaceOptions");
                }
            } catch (PutException pe) {
                // For other errors, we try this also on the
                try {
                    boolean optionsMatch;
                    try {
                        optionsMatch = verifyNamespaceProperties(namespace, nsProperties);
                        if (!optionsMatch) {
                            throw new NamespaceCreationException("Namespace already created with incompatible properties");
                        }
                    } catch (NamespaceNotCreatedException nnce) {
                        // Should not be possible any more, but leave old retry in for now.
                        retry = true;
                    } catch (RuntimeException re) {
                        Log.logErrorWarning(re);
                        Log.warning(pe.getDetailedFailureMessage());
                        Log.logErrorWarning(pe, "Couldn't store options due to exception");
                    }
                } catch (RetrievalException re) {
                    Log.warning("storeNamespaceProperties failing");
                    Log.warning("PutException");
                    pe.printStackTrace();
                    Log.warning("RetrievalException");
                    re.printStackTrace();
                    throw new NamespaceCreationException(re);
                }
            }
        }
    } while (retry);
}
Also used : PutException(com.ms.silverking.cloud.dht.client.PutException) RetrievalException(com.ms.silverking.cloud.dht.client.RetrievalException) NamespaceNotCreatedException(com.ms.silverking.cloud.dht.daemon.storage.NamespaceNotCreatedException) NamespaceCreationException(com.ms.silverking.cloud.dht.client.NamespaceCreationException)

Aggregations

PutException (com.ms.silverking.cloud.dht.client.PutException)9 VersionConstraint (com.ms.silverking.cloud.dht.VersionConstraint)7 ImmutableMap (com.google.common.collect.ImmutableMap)3 PutOptions (com.ms.silverking.cloud.dht.PutOptions)3 ImmutableSet (com.google.common.collect.ImmutableSet)1 AsyncPut (com.ms.silverking.cloud.dht.client.AsyncPut)1 NamespaceCreationException (com.ms.silverking.cloud.dht.client.NamespaceCreationException)1 OperationException (com.ms.silverking.cloud.dht.client.OperationException)1 RetrievalException (com.ms.silverking.cloud.dht.client.RetrievalException)1 NamespaceNotCreatedException (com.ms.silverking.cloud.dht.daemon.storage.NamespaceNotCreatedException)1