protected static void waitForSchemaAgreement(Cassandra.Client cassandra) throws InvalidRequestException, TException, InterruptedException { int waited = 0; int versions = 0; while (versions != 1) { versions = 0; Map<String, List<String>> schema = cassandra.describe_schema_versions(); for (Map.Entry<String, List<String>> entry : schema.entrySet()) { if (!entry.getKey().equals("UNREACHABLE")) versions++; } if (versions != 1) { Thread.sleep(WAIT_FOR_SCHEMA_AGREEMENT_SLEEP_TIME); waited += WAIT_FOR_SCHEMA_AGREEMENT_SLEEP_TIME; if (waited > RING_DELAY) throw new RuntimeException("Could not reach schema agreement in " + RING_DELAY + "ms"); } } }
protected static void waitForSchemaAgreement(Cassandra.Client cassandra) throws InvalidRequestException, TException, InterruptedException { int waited = 0; int versions = 0; while (versions != 1) { versions = 0; Map<String, List<String>> schema = cassandra.describe_schema_versions(); for (Map.Entry<String, List<String>> entry : schema.entrySet()) { if (!entry.getKey().equals("UNREACHABLE")) versions++; } if (versions != 1) { Thread.sleep(WAIT_FOR_SCHEMA_AGREEMENT_SLEEP_TIME); waited += WAIT_FOR_SCHEMA_AGREEMENT_SLEEP_TIME; if (waited > RING_DELAY) throw new RuntimeException("Could not reach schema agreement in " + RING_DELAY + "ms"); } } }
private void waitForSchemaPropagation(DBConn dbConn) { for(int i = 0; i < 5; i++) { try { Map<String, List<String>> versions = dbConn.getClientSession().describe_schema_versions(); if(versions.size() <= 1) return; m_logger.info("Schema versions are not synchronized yet. Retrying"); Thread.sleep(500 + 1000 * i); }catch(Exception ex) { m_logger.warn("Error waiting for schema propagation: {}", ex.getMessage()); } m_logger.error("Schema versions have not been synchronized"); } }
public static void main(String[] args) { TSocket socket = new TSocket("192.168.0.100", 9160); TBinaryProtocol tBinaryProtocol = new TBinaryProtocol(socket, true, true); TTransport transport = socket; try { transport.open(); Cassandra.Client client = new Cassandra.Client(tBinaryProtocol); Map<String, List<String>> schemaVersions= client.describe_schema_versions(); transport.close(); } catch (TTransportException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (TException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (InvalidRequestException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } }
/** * Do a quick check to see if there is a schema disagreement. This is done as an extra precaution * to reduce the chances of putting the cluster into a bad state. This will not gurantee however, that * by the time a schema change is made the cluster will be in the same state. * @param client * @throws Exception */ private void precheckSchemaAgreement(Client client) throws Exception { Map<String, List<String>> schemas = client.describe_schema_versions(); if (schemas.size() > 1) { throw new SchemaDisagreementException("Can't change schema due to pending schema agreement"); } } }
/** * Do a quick check to see if there is a schema disagreement. This is done as an extra precaution * to reduce the chances of putting the cluster into a bad state. This will not gurantee however, that * by the time a schema change is made the cluster will be in the same state. * @param client * @throws Exception */ private void precheckSchemaAgreement(Client client) throws Exception { Map<String, List<String>> schemas = client.describe_schema_versions(); if (schemas.size() > 1) { throw new SchemaDisagreementException("Can't change schema due to pending schema agreement"); } } }
/** * Do a quick check to see if there is a schema disagreement. This is done as an extra precaution * to reduce the chances of putting the cluster into a bad state. This will not gurantee however, that * by the time a schema change is made the cluster will be in the same state. * @param client * @throws Exception */ private void precheckSchemaAgreement(Client client) throws Exception { Map<String, List<String>> schemas = client.describe_schema_versions(); if (schemas.size() > 1) { throw new SchemaDisagreementException("Can't change schema due to pending schema agreement"); } }
@Override public Map<String, List<String>> describe_schema_versions() throws InvalidRequestException, TException { return executeHandlingExceptions(() -> client.describe_schema_versions()); }
/** * Do a quick check to see if there is a schema disagreement. This is done as an extra precaution * to reduce the chances of putting the cluster into a bad state. This will not gurantee however, that * by the time a schema change is made the cluster will be in the same state. * @param client * @throws Exception */ private void precheckSchemaAgreement(Client client) throws Exception { Map<String, List<String>> schemas = client.describe_schema_versions(); if (schemas.size() > 1) { throw new SchemaDisagreementException("Can't change schema due to pending schema agreement"); } }
@Override public Map<String, List<String>> internalExecute(Client client, ConnectionContext context) throws Exception { return client.describe_schema_versions(); } }, config.getRetryPolicy().duplicate()).getResult();
@Override public Map<String, List<String>> describe_schema_versions() throws InvalidRequestException, TException { return client.describe_schema_versions(); }
@Override public Map<String, List<String>> internalExecute(Client client, ConnectionContext context) throws Exception { return client.describe_schema_versions(); } }, config.getRetryPolicy().duplicate()).getResult();
@Override public Map<String,List<String>> execute(Cassandra.Client cassandra) throws HectorException { try { return cassandra.describe_schema_versions(); } catch (Exception e) { throw xtrans.translate(e); } } };
@Override public Map<String, List<String>> internalExecute(Client client, ConnectionContext context) throws Exception { return client.describe_schema_versions(); } }, config.getRetryPolicy().duplicate()).getResult();
@Override public Map<String,List<String>> execute(Cassandra.Client cassandra) throws HectorException { try { return cassandra.describe_schema_versions(); } catch (Exception e) { throw xtrans.translate(e); } } };
@Override public Map<String, List<String>> describe_schema_versions() throws InvalidRequestException, TException { return client.describe_schema_versions(); }
@Override public Map<String, List<String>> internalExecute(Client client, ConnectionContext context) throws Exception { return client.describe_schema_versions(); } }, config.getRetryPolicy().duplicate()).getResult();
@Override public Map<String, List<String>> describe_schema_versions() throws InvalidRequestException, TException { return executeHandlingExceptions(() -> client.describe_schema_versions()); }
@Override public Map<String, List<String>> describe_schema_versions() throws InvalidRequestException, TException { return client.describe_schema_versions(); }
@Override public Map<String,List<String>> execute(Cassandra.Client cassandra) throws HectorException { try { return cassandra.describe_schema_versions(); } catch (Exception e) { throw xtrans.translate(e); } } };