Search in sources :

Example 1 with NamespaceCreationException

use of com.ms.silverking.cloud.dht.client.NamespaceCreationException 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

NamespaceCreationException (com.ms.silverking.cloud.dht.client.NamespaceCreationException)1 PutException (com.ms.silverking.cloud.dht.client.PutException)1 RetrievalException (com.ms.silverking.cloud.dht.client.RetrievalException)1 NamespaceNotCreatedException (com.ms.silverking.cloud.dht.daemon.storage.NamespaceNotCreatedException)1