예제 #1
0
 public Socket newSocket() throws IOException {
   // zero means 'bind on any available port.'
   if (isEncryptedChannel()) {
     if (Config.getOutboundBindAny())
       return SSLFactory.getSocket(
           DatabaseDescriptor.getEncryptionOptions(),
           endPoint(),
           DatabaseDescriptor.getSSLStoragePort());
     else
       return SSLFactory.getSocket(
           DatabaseDescriptor.getEncryptionOptions(),
           endPoint(),
           DatabaseDescriptor.getSSLStoragePort(),
           FBUtilities.getLocalAddress(),
           0);
   } else {
     if (Config.getOutboundBindAny())
       return new Socket(endPoint(), DatabaseDescriptor.getStoragePort());
     else
       return new Socket(
           endPoint(), DatabaseDescriptor.getStoragePort(), FBUtilities.getLocalAddress(), 0);
   }
 }
 public Socket newSocket() throws IOException {
   // zero means 'bind on any available port.'
   if (isEncryptedChannel()) {
     if (Config.getOutboundBindAny())
       return SSLFactory.getSocket(
           DatabaseDescriptor.getServerEncryptionOptions(),
           endPoint(),
           DatabaseDescriptor.getSSLStoragePort());
     else
       return SSLFactory.getSocket(
           DatabaseDescriptor.getServerEncryptionOptions(),
           endPoint(),
           DatabaseDescriptor.getSSLStoragePort(),
           FBUtilities.getLocalAddress(),
           0);
   } else {
     Socket socket =
         SocketChannel.open(new InetSocketAddress(endPoint(), DatabaseDescriptor.getStoragePort()))
             .socket();
     if (Config.getOutboundBindAny() && !socket.isBound())
       socket.bind(new InetSocketAddress(FBUtilities.getLocalAddress(), 0));
     return socket;
   }
 }
  public static void main(String args[]) {
    Config.setClientMode(true);
    LoaderOptions options = LoaderOptions.parseArgs(args);
    OutputHandler handler = new OutputHandler.SystemOutput(options.verbose, options.debug);
    SSTableLoader loader =
        new SSTableLoader(
            options.directory,
            new ExternalClient(
                options.hosts,
                options.rpcPort,
                options.user,
                options.passwd,
                options.transportFactory,
                options.storagePort,
                options.sslStoragePort,
                options.serverEncOptions),
            handler);
    DatabaseDescriptor.setStreamThroughputOutboundMegabitsPerSec(options.throttle);
    StreamResultFuture future = null;
    try {
      if (options.noProgress) future = loader.stream(options.ignores);
      else future = loader.stream(options.ignores, new ProgressIndicator());
    } catch (Exception e) {
      System.err.println(e.getMessage());
      if (e.getCause() != null) System.err.println(e.getCause());
      if (options.debug) e.printStackTrace(System.err);
      else System.err.println("Run with --debug to get full stack trace or --help to get help.");
      System.exit(1);
    }

    handler.output(String.format("Streaming session ID: %s", future.planId));

    try {
      future.get();
      System.exit(0); // We need that to stop non daemonized threads
    } catch (Exception e) {
      System.err.println("Streaming to the following hosts failed:");
      System.err.println(loader.getFailedHosts());
      System.err.println(e);
      if (options.debug) e.printStackTrace(System.err);
      System.exit(1);
    }
  }
예제 #4
0
  @Override
  public void start() throws Exception {
    if (_app != null) {

      initThreadUncaughtExceptionHandler();

      initServer();
      initSysClientFactory();
      _server.start();

      // only data node needs to poll the cluster's address change
      if (!_coordinator.isControlNode()) {
        _clusterPoller.start();
      }

      startNewVersionCheck();
      startUpgradeManager();
      startSecretsManager();
      startPropertyManager();
      startVdcManager();
      startIpReconfigManager();

      // config cassandra as client mode to avoid load yaml file
      Config.setClientMode(true);

      DrUtil drUtil = _coordinator.getDrUtil();
      if (drUtil.isActiveSite()) {
        _recoveryMgr.init();
        startSystemAudit(_dbClient);
      }
      _svcBeacon.start();

      if (drUtil.isActiveSite()) {
        startNetworkMonitor();
      }
    } else {
      throw new Exception("No app found.");
    }
  }
예제 #5
0
  static {
    Config.setClientMode(true);

    Option optKey = new Option(KEY_OPTION, true, "Partition key");
    // Number of times -k <key> can be passed on the command line.
    optKey.setArgs(500);
    options.addOption(optKey);

    Option excludeKey = new Option(EXCLUDE_KEY_OPTION, true, "Excluded partition key");
    // Number of times -x <key> can be passed on the command line.
    excludeKey.setArgs(500);
    options.addOption(excludeKey);

    Option optEnumerate = new Option(ENUMERATE_KEYS_OPTION, false, "enumerate partition keys only");
    options.addOption(optEnumerate);

    Option debugOutput =
        new Option(DEBUG_OUTPUT_OPTION, false, "CQL row per line internal representation");
    options.addOption(debugOutput);

    Option rawTimestamps =
        new Option(RAW_TIMESTAMPS, false, "Print raw timestamps instead of iso8601 date strings");
    options.addOption(rawTimestamps);
  }
  private static List<RawKeyspace> readTablesFromXml(XMLUtils xmlUtils)
      throws ConfigurationException {

    List<RawKeyspace> keyspaces = new ArrayList<RawKeyspace>();
    /* Read the table related stuff from config */
    try {
      String endPointSnitchClassName = null; // Used as a sentinel. EPS cannot be undefined in 0.6.
      NodeList tablesxml = xmlUtils.getRequestedNodeList("/Storage/Keyspaces/Keyspace");

      String gcGrace = xmlUtils.getNodeValue("/Storage/GCGraceSeconds");
      int gc_grace_seconds = 864000;
      if (gcGrace != null) gc_grace_seconds = Integer.parseInt(gcGrace);

      int size = tablesxml.getLength();
      for (int i = 0; i < size; ++i) {
        String value;
        RawKeyspace ks = new RawKeyspace();
        Node table = tablesxml.item(i);
        /* parsing out the table ksName */
        ks.name = XMLUtils.getAttributeValue(table, "Name");

        value =
            xmlUtils.getNodeValue(
                "/Storage/Keyspaces/Keyspace[@Name='" + ks.name + "']/EndPointSnitch");
        if (endPointSnitchClassName == null) {
          endPointSnitchClassName = value;
        } else if (!endPointSnitchClassName.equals(value)) {
          throw new ConfigurationException(
              "ERROR : EndPointSnitch is global in 0.7 -- multiple choices present.");
        }

        ks.replica_placement_strategy =
            xmlUtils.getNodeValue(
                "/Storage/Keyspaces/Keyspace[@Name='" + ks.name + "']/ReplicaPlacementStrategy");
        /* Data replication factor */
        value =
            xmlUtils.getNodeValue(
                "/Storage/Keyspaces/Keyspace[@Name='" + ks.name + "']/ReplicationFactor");
        if (value != null) {
          ks.replication_factor = Integer.parseInt(value);
        }

        String xqlTable = "/Storage/Keyspaces/Keyspace[@Name='" + ks.name + "']/";
        NodeList columnFamilies = xmlUtils.getRequestedNodeList(xqlTable + "ColumnFamily");

        int size2 = columnFamilies.getLength();
        ks.column_families = new RawColumnFamily[size2];
        for (int j = 0; j < size2; ++j) {
          Node columnFamily = columnFamilies.item(j);
          ks.column_families[j] = new RawColumnFamily();
          ks.column_families[j].name = XMLUtils.getAttributeValue(columnFamily, "Name");
          String xqlCF = xqlTable + "ColumnFamily[@Name='" + ks.column_families[j].name + "']/";
          ks.column_families[j].column_type =
              ColumnFamilyType.create(XMLUtils.getAttributeValue(columnFamily, "ColumnType"));
          ks.column_families[j].compare_with =
              XMLUtils.getAttributeValue(columnFamily, "CompareWith");

          if (ks.column_families[j].column_type != null
              && ks.column_families[j].column_type == ColumnFamilyType.Super)
            ks.column_families[j].compare_subcolumns_with =
                XMLUtils.getAttributeValue(columnFamily, "CompareSubcolumnsWith");

          if ((value = XMLUtils.getAttributeValue(columnFamily, "KeysCached")) != null) {
            ks.column_families[j].keys_cached = FBUtilities.parseDoubleOrPercent(value);
          }

          if ((value = XMLUtils.getAttributeValue(columnFamily, "RowsCached")) != null) {
            ks.column_families[j].rows_cached = FBUtilities.parseDoubleOrPercent(value);
          }

          if ((value = XMLUtils.getAttributeValue(columnFamily, "ReadRepairChance")) != null) {
            ks.column_families[j].read_repair_chance = FBUtilities.parseDoubleOrPercent(value);
          }

          ks.column_families[j].gc_grace_seconds = gc_grace_seconds;

          ks.column_families[j].comment = xmlUtils.getNodeValue(xqlCF + "Comment");
        }
        keyspaces.add(ks);
      }
      if (endPointSnitchClassName.equals("org.apache.cassandra.locator.EndPointSnitch")) {
        endPointSnitchClassName = "org.apache.cassandra.locator.RackInferringSnitch";
        System.out.println(
            "WARN : org.apache.cassandra.locator.EndPointSnitch has been replaced by org.apache.cassandra.locator.RackInferringSnitch");
      } else if (endPointSnitchClassName.equals(
          "org.apache.cassandra.locator.PropertyFileEndpointSnitch")) {
        endPointSnitchClassName = "org.apache.cassandra.locator.PropertyFileSnitch";
        System.out.println(
            "WARN : org.apache.cassandra.locator.PropertyFileEndpointSnich has been replaced by org.apache.cassandra.locator.PropertyFileSnitch");
      } else {
        System.out.println("INFO : EndPointSnitch is global in 0.7 and may need to be updated.");
      }
      conf.endpoint_snitch = endPointSnitchClassName;
      return keyspaces;
    } catch (XPathExpressionException e) {
      throw new ConfigurationException("XPath expression error.");
    } catch (TransformerException e) {
      throw new ConfigurationException("Error occurred during the transformation process.");
    }
  }
  private static void loadPreviousConfig(String config) throws ConfigurationException {
    try {
      XMLUtils xmlUtils = new XMLUtils(config);
      conf.cluster_name = xmlUtils.getNodeValue("/Storage/ClusterName");

      String syncRaw = xmlUtils.getNodeValue("/Storage/CommitLogSync");
      conf.commitlog_sync = Config.CommitLogSync.valueOf(syncRaw);

      if (conf.commitlog_sync != null) {
        if (conf.commitlog_sync == Config.CommitLogSync.batch)
          conf.commitlog_sync_batch_window_in_ms =
              Double.valueOf(xmlUtils.getNodeValue("/Storage/CommitLogSyncBatchWindowInMS"));
        else
          conf.commitlog_sync_period_in_ms =
              Integer.valueOf(xmlUtils.getNodeValue("/Storage/CommitLogSyncPeriodInMS"));
      }

      String modeRaw = xmlUtils.getNodeValue("/Storage/DiskAccessMode");
      conf.disk_access_mode = Config.DiskAccessMode.valueOf(modeRaw);

      conf.authenticator = xmlUtils.getNodeValue("/Storage/Authenticator");
      // handle the authc/authz split by configuring SimpleAuthority if SimpleAuthenticator is in
      // use
      if (conf.authenticator != null
          && conf.authenticator.equals(SimpleAuthenticator.class.getName()))
        conf.authority = SimpleAuthority.class.getName();

      /* Hashing strategy */
      conf.partitioner = xmlUtils.getNodeValue("/Storage/Partitioner");

      conf.job_tracker_host = xmlUtils.getNodeValue("/Storage/JobTrackerHost");

      conf.job_jar_file_location = xmlUtils.getNodeValue("/Storage/JobJarFileLocation");

      conf.initial_token = xmlUtils.getNodeValue("/Storage/InitialToken");

      String rpcTimeout = xmlUtils.getNodeValue("/Storage/RpcTimeoutInMillis");
      if (rpcTimeout != null) conf.rpc_timeout_in_ms = Long.parseLong(rpcTimeout);

      String rawReaders = xmlUtils.getNodeValue("/Storage/ConcurrentReads");
      if (rawReaders != null) {
        conf.concurrent_reads = Integer.parseInt(rawReaders);
      }

      String rawWriters = xmlUtils.getNodeValue("/Storage/ConcurrentWrites");
      if (rawWriters != null) {
        conf.concurrent_writes = Integer.parseInt(rawWriters);
      }

      String rawSlicedBuffer = xmlUtils.getNodeValue("/Storage/SlicedBufferSizeInKB");
      if (rawSlicedBuffer != null) {
        conf.sliced_buffer_size_in_kb = Integer.parseInt(rawSlicedBuffer);
      }

      String bmtThresh = xmlUtils.getNodeValue("/Storage/BinaryMemtableThroughputInMB");
      if (bmtThresh != null) {
        conf.binary_memtable_throughput_in_mb = Integer.parseInt(bmtThresh);
      }

      /* TCP port on which the storage system listens */
      String port = xmlUtils.getNodeValue("/Storage/StoragePort");
      if (port != null) conf.storage_port = Integer.parseInt(port);

      /* Local IP or hostname to bind services to */
      conf.listen_address = xmlUtils.getNodeValue("/Storage/ListenAddress");

      conf.rpc_address = xmlUtils.getNodeValue("/Storage/RPCAddress");

      port = xmlUtils.getNodeValue("/Storage/RPCPort");
      if (port != null) conf.rpc_port = Integer.parseInt(port);

      String framedRaw = xmlUtils.getNodeValue("/Storage/ThriftFramedTransport");
      if (framedRaw != null && !Boolean.valueOf(framedRaw)) {
        conf.thrift_framed_transport_size_in_mb = 0;
        System.out.println(
            "WARN : Thrift uses framed Transport by default in 0.7! Setting TFramedTransportSize to 0MB (disabled).");
      } else {
        conf.thrift_framed_transport_size_in_mb = 15;
        System.out.println("TFramedTransport will have a maximum frame size of 15MB");
      }

      String sbc = xmlUtils.getNodeValue("/Storage/SnapshotBeforeCompaction");
      if (sbc != null) {
        conf.snapshot_before_compaction = Boolean.valueOf(sbc);
      }

      String autoBootstr = xmlUtils.getNodeValue("/Storage/AutoBootstrap");
      if (autoBootstr != null) {
        conf.auto_bootstrap = Boolean.valueOf(autoBootstr);
      }

      String lifetime = xmlUtils.getNodeValue("/Storage/MemtableFlushAfterMinutes");
      if (lifetime != null) conf.memtable_flush_after_mins = Integer.parseInt(lifetime);

      String memtableSize = xmlUtils.getNodeValue("/Storage/MemtableThroughputInMB");
      if (memtableSize != null) conf.memtable_throughput_in_mb = Integer.parseInt(memtableSize);

      String memtableObjectCount = xmlUtils.getNodeValue("/Storage/MemtableOperationsInMillions");
      if (memtableObjectCount != null)
        conf.memtable_operations_in_millions = Double.parseDouble(memtableObjectCount);

      String columnIndexSize = xmlUtils.getNodeValue("/Storage/ColumnIndexSizeInKB");
      if (columnIndexSize != null) {
        conf.column_index_size_in_kb = Integer.parseInt(columnIndexSize);
      }

      conf.data_file_directories =
          xmlUtils.getNodeValues("/Storage/DataFileDirectories/DataFileDirectory");

      conf.commitlog_directory = xmlUtils.getNodeValue("/Storage/CommitLogDirectory");

      String value = xmlUtils.getNodeValue("/Storage/CommitLogRotationThresholdInMB");
      if (value != null) conf.commitlog_rotation_threshold_in_mb = Integer.parseInt(value);

      conf.seeds = xmlUtils.getNodeValues("/Storage/Seeds/Seed");

      conf.keyspaces = readTablesFromXml(xmlUtils);
    } catch (ParserConfigurationException e) {
      System.out.println("Parser error during previous config load.");
      throw new ConfigurationException("Parser error during previous config load.");
    } catch (SAXException e) {
      System.out.println("SAX error during previous config load.");
      throw new ConfigurationException("SAX error during previous config load.");
    } catch (IOException e) {
      System.out.println("File I/O error during previous config load.");
      throw new ConfigurationException("File I/O error during previous config load.");
    } catch (XPathExpressionException e) {
      System.out.println("XPath error during previous config load.");
      throw new ConfigurationException("XPath error during previous config load.");
    }
  }