Пример #1
0
 Map<String, Map<String, String>> getCFMetaData(String keyspace)
     throws NotFoundException, TException {
   // Lazily lookup column family meta-data.
   if (!(keyspacesMap.containsKey(keyspace)))
     keyspacesMap.put(keyspace, thriftClient_.describe_keyspace(keyspace));
   return keyspacesMap.get(keyspace);
 }
Пример #2
0
  // process a statement of the form: describe table <tablename>
  private void executeDescribeTable(CommonTree ast) throws TException {
    if (!CliMain.isConnected()) return;

    // Get table name
    int childCount = ast.getChildCount();
    assert (childCount == 1);

    String tableName = ast.getChild(0).getText();

    if (tableName == null) {
      css_.out.println("Keyspace argument required");
      return;
    }

    // Describe and display
    Map<String, Map<String, String>> columnFamiliesMap;
    try {
      columnFamiliesMap = thriftClient_.describe_keyspace(tableName);
      for (String columnFamilyName : columnFamiliesMap.keySet()) {
        Map<String, String> columnMap = columnFamiliesMap.get(columnFamilyName);
        String desc = columnMap.get("Desc");
        String columnFamilyType = columnMap.get("Type");
        String sort = columnMap.get("CompareWith");
        String flushperiod = columnMap.get("FlushPeriodInMinutes");
        css_.out.println(desc);
        css_.out.println("Column Family Type: " + columnFamilyType);
        css_.out.println("Column Sorted By: " + sort);
        css_.out.println("flush period: " + flushperiod + " minutes");
        css_.out.println("------");
      }
    } catch (NotFoundException e) {
      css_.out.println("Keyspace " + tableName + " could not be found.");
    }
  }
 @Test
 public void connectToKeyspace() throws Exception {
   TTransport tr =
       new TFramedTransport(new TSocket("localhost", Integer.getInteger("rpcPort", 9160)));
   TProtocol proto = new TBinaryProtocol(tr);
   Cassandra.Client client = new Cassandra.Client(proto);
   tr.open();
   try {
     assertThat(
         client.describe_keyspace("TestKeyspace").getStrategy_options().entrySet(),
         hasItem(
             (Map.Entry<String, String>)
                 new AbstractMap.SimpleEntry<String, String>("replication_factor", "1")));
   } finally {
     tr.close();
   }
 }
Пример #4
0
 /*
  * This keyspace exists because we need a way to pull the datacenter information and they only
  * way to do it is if you have a valid keyspace set up.  We will pull the info from here
  * so we can accurately create the actually NetworkTopologyStrategy keyspace.
  */
 private static void ensureTestKeyspaceExists(Cassandra.Client client) {
   try {
     try {
       client.describe_keyspace(CassandraConstants.SIMPLE_RF_TEST_KEYSPACE);
       return;
     } catch (NotFoundException e) {
       // need to create key space
     }
     KsDef testKs =
         new KsDef(
             CassandraConstants.SIMPLE_RF_TEST_KEYSPACE,
             CassandraConstants.SIMPLE_STRATEGY,
             ImmutableList.<CfDef>of());
     testKs.setStrategy_options(
         ImmutableMap.of(CassandraConstants.REPLICATION_FACTOR_OPTION, "1"));
     client.system_add_keyspace(testKs);
   } catch (Exception e) {
     log.warn(e.getMessage(), e);
   }
 }
Пример #5
0
  // This method exists to verify a particularly nasty bug where cassandra doesn't have a
  // consistent ring across all of it's nodes.  One node will think it owns more than the others
  // think it does and they will not send writes to it, but it will respond to requests
  // acting like it does.
  protected static void sanityCheckRingConsistency(
      Set<String> currentHosts,
      int port,
      String keyspace,
      boolean isSsl,
      boolean safetyDisabled,
      int socketTimeoutMillis,
      int socketQueryTimeoutMillis) {
    Multimap<Set<TokenRange>, String> tokenRangesToHost = HashMultimap.create();
    for (String host : currentHosts) {
      Cassandra.Client client = null;
      try {
        client =
            CassandraClientPoolingContainer.getClientInternal(
                host, port, isSsl, socketTimeoutMillis, socketQueryTimeoutMillis);
        try {
          client.describe_keyspace(keyspace);
        } catch (NotFoundException e) {
          log.warn(
              "Tried to check ring consistency for node "
                  + host
                  + " before keyspace was fully setup; aborting check for now.",
              e);
          return;
        }
        tokenRangesToHost.put(ImmutableSet.copyOf(client.describe_ring(keyspace)), host);
      } catch (Exception e) {
        log.warn("failed to get ring info from host: {}", host, e);
      } finally {
        if (client != null) {
          client.getOutputProtocol().getTransport().close();
        }
      }
    }

    if (tokenRangesToHost.isEmpty()) {
      log.error(
          "Failed to get ring info for entire Cassandra cluster ("
              + keyspace
              + "); ring could not be checked for consistency.");
      return;
    }

    if (tokenRangesToHost.keySet().size() == 1) {
      return;
    }

    RuntimeException e =
        new IllegalStateException(
            "Hosts have differing ring descriptions.  This can lead to inconsistent reads and lost data. ");
    log.error("QA-86204 " + e.getMessage() + tokenRangesToHost, e);

    if (tokenRangesToHost.size() > 2) {
      for (Entry<Set<TokenRange>, Collection<String>> entry :
          tokenRangesToHost.asMap().entrySet()) {
        if (entry.getValue().size() == 1) {
          log.error(
              "Host: "
                  + entry.getValue().iterator().next()
                  + " disagrees with the other nodes about the ring state.");
        }
      }
    }

    if (tokenRangesToHost.keySet().size() == 2) {
      ImmutableList<Set<TokenRange>> sets = ImmutableList.copyOf(tokenRangesToHost.keySet());
      Set<TokenRange> set1 = sets.get(0);
      Set<TokenRange> set2 = sets.get(1);
      log.error(
          "Hosts are split.  group1: "
              + tokenRangesToHost.get(set1)
              + " group2: "
              + tokenRangesToHost.get(set2));
    }

    logErrorOrThrow(e.getMessage(), safetyDisabled);
  }