示例#1
0
  /**
   * Read schema from system table and calculate MD5 digest of every row, resulting digest will be
   * converted into UUID which would act as content-based version of the schema.
   */
  public void updateVersion() {
    try {
      MessageDigest versionDigest = MessageDigest.getInstance("MD5");

      for (Row row : SystemTable.serializedSchema()) {
        if (invalidSchemaRow(row) || ignoredSchemaRow(row)) continue;

        row.cf.updateDigest(versionDigest);
      }

      version = UUID.nameUUIDFromBytes(versionDigest.digest());
      SystemTable.updateSchemaVersion(version);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
示例#2
0
  public RowMutation dropFromSchema(long timestamp) {
    RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, SystemTable.getSchemaKSKey(name));
    rm.delete(new QueryPath(SystemTable.SCHEMA_KEYSPACES_CF), timestamp);
    rm.delete(new QueryPath(SystemTable.SCHEMA_COLUMNFAMILIES_CF), timestamp);
    rm.delete(new QueryPath(SystemTable.SCHEMA_COLUMNS_CF), timestamp);

    return rm;
  }
示例#3
0
  public KSMetaData reloadAttributes() throws IOException {
    Row ksDefRow = SystemTable.readSchemaRow(name);

    if (ksDefRow.cf == null)
      throw new IOException(
          String.format(
              "%s not found in the schema definitions table (%s).",
              name, SystemTable.SCHEMA_KEYSPACES_CF));

    return fromSchema(ksDefRow, Collections.<CFMetaData>emptyList());
  }
示例#4
0
  public RowMutation toSchema(long timestamp) {
    RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, SystemTable.getSchemaKSKey(name));
    ColumnFamily cf = rm.addOrGet(SystemTable.SCHEMA_KEYSPACES_CF);

    cf.addColumn(Column.create(name, timestamp, "name"));
    cf.addColumn(Column.create(durableWrites, timestamp, "durable_writes"));
    cf.addColumn(Column.create(strategyClass.getName(), timestamp, "strategy_class"));
    cf.addColumn(Column.create(json(strategyOptions), timestamp, "strategy_options"));

    for (CFMetaData cfm : cfMetaData.values()) cfm.toSchema(rm, timestamp);

    return rm;
  }
示例#5
0
  @Override
  public void applyModels() throws IOException {
    KSMetaData ksm = DatabaseDescriptor.getTableDefinition(name);
    // remove the table from the static instances.
    Table table = Table.clear(ksm.name);
    if (table == null) throw new IOException("Table is not active. " + ksm.name);

    // remove all cfs from the table instance.
    for (CFMetaData cfm : ksm.cfMetaData().values()) {
      CFMetaData.purge(cfm);
      table.dropCf(cfm.cfId);
      SystemTable.markForRemoval(cfm);
    }

    // reset defs.
    DatabaseDescriptor.clearTableDefinition(ksm, newVersion);
    CommitLog.instance().forceNewSegment();
    Migration.cleanupDeadFiles(blockOnFileDeletion);

    // clear up any local hinted data for this keyspace.
    HintedHandOffManager.renameHints(name, null);
  }