Java Code Examples for org.apache.helix.store.zk.ZkHelixPropertyStore#get()

The following examples show how to use org.apache.helix.store.zk.ZkHelixPropertyStore#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZKMetadataProvider.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
@Nullable
public static RealtimeSegmentZKMetadata getRealtimeSegmentZKMetadata(
    @Nonnull ZkHelixPropertyStore<ZNRecord> propertyStore, @Nonnull String tableName, @Nonnull String segmentName) {
  String realtimeTableName = TableNameBuilder.REALTIME.tableNameWithType(tableName);
  ZNRecord znRecord = propertyStore
      .get(constructPropertyStorePathForSegment(realtimeTableName, segmentName), null, AccessOption.PERSISTENT);
  // It is possible that the segment metadata has just been deleted due to retention.
  if (znRecord == null) {
    return null;
  }
  if (SegmentName.isHighLevelConsumerSegmentName(segmentName)) {
    return new RealtimeSegmentZKMetadata(znRecord);
  } else {
    return new LLCRealtimeSegmentZKMetadata(znRecord);
  }
}
 
Example 2
Source File: FileStoreStateModel.java    From helix with Apache License 2.0 5 votes vote down vote up
/**
 * When the node becomes master, it will start accepting writes and increments
 * the epoch and starts logging the changes in a file
 * @param message
 * @param context
 * @throws Exception
 */
@Transition(from = "SLAVE", to = "MASTER")
public void onBecomeMasterFromSlave(final Message message, NotificationContext context)
    throws Exception {
  replicator.stop();
  System.out.println(_serverId + " transitioning from " + message.getFromState() + " to "
      + message.getToState() + " for " + _partition);
  ZkHelixPropertyStore<ZNRecord> helixPropertyStore =
      context.getManager().getHelixPropertyStore();
  String checkpointDirPath = instanceConfig.getRecord().getSimpleField("check_point_dir");
  CheckpointFile checkpointFile = new CheckpointFile(checkpointDirPath);
  final ChangeRecord lastRecordProcessed = checkpointFile.findLastRecordProcessed();
  DataUpdater<ZNRecord> updater = new HighWaterMarkUpdater(message, lastRecordProcessed);
  helixPropertyStore.update("/TRANSACTION_ID_METADATA" + "/" + message.getResourceName(),
      updater, AccessOption.PERSISTENT);
  Stat stat = new Stat();
  ;
  ZNRecord znRecord =
      helixPropertyStore.get("/TRANSACTION_ID_METADATA" + "/" + message.getResourceName(), stat,
          AccessOption.PERSISTENT);
  int startGen = Integer.parseInt(znRecord.getSimpleField("currentGen"));
  int startSeq = Integer.parseInt(znRecord.getSimpleField("currentGenStartSeq"));
  String fileStoreDir = instanceConfig.getRecord().getSimpleField("file_store_dir");
  String changeLogDir = instanceConfig.getRecord().getSimpleField("change_log_dir");

  generator = new ChangeLogGenerator(changeLogDir, startGen, startSeq);
  // To indicate that we need callbacks for changes that happen starting now
  long now = System.currentTimeMillis();
  service = new FileSystemWatchService(fileStoreDir, now, generator);
  service.start();
  System.out.println(_serverId + " transitioned from " + message.getFromState() + " to "
      + message.getToState() + " for " + _partition);
}
 
Example 3
Source File: MoveReplicaGroup.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
private TableConfig getTableConfig(String tableName)
    throws IOException {
  ZNRecordSerializer serializer = new ZNRecordSerializer();
  String path = PropertyPathConfig.getPath(PropertyType.PROPERTYSTORE, zkPath);
  ZkHelixPropertyStore<ZNRecord> propertyStore = new ZkHelixPropertyStore<>(zkHost, serializer, path);
  ZNRecord tcZnRecord = propertyStore.get("/CONFIGS/TABLE/" + tableName, null, 0);
  TableConfig tableConfig = TableConfigUtils.fromZNRecord(tcZnRecord);
  LOGGER.debug("Loaded table config");
  return tableConfig;
}
 
Example 4
Source File: SegmentLineageAccessHelper.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Read the segment lineage ZNRecord from the property store
 *
 * @param propertyStore a property store
 * @param tableNameWithType a table name with type
 * @return a ZNRecord of segment merge lineage, return null if znode does not exist
 */
public static ZNRecord getSegmentLineageZNRecord(ZkHelixPropertyStore<ZNRecord> propertyStore,
    String tableNameWithType) {
  String path = ZKMetadataProvider.constructPropertyStorePathForSegmentLineage(tableNameWithType);
  Stat stat = new Stat();
  ZNRecord segmentLineageZNRecord = propertyStore.get(path, stat, AccessOption.PERSISTENT);
  if (segmentLineageZNRecord != null) {
    segmentLineageZNRecord.setVersion(stat.getVersion());
  }
  return segmentLineageZNRecord;
}
 
Example 5
Source File: ZKMetadataProvider.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public static InstanceZKMetadata getInstanceZKMetadata(ZkHelixPropertyStore<ZNRecord> propertyStore,
    String instanceId) {
  ZNRecord znRecord = propertyStore
      .get(StringUtil.join("/", PROPERTYSTORE_INSTANCE_CONFIGS_PREFIX, instanceId), null, AccessOption.PERSISTENT);
  if (znRecord == null) {
    return null;
  }
  return new InstanceZKMetadata(znRecord);
}
 
Example 6
Source File: ZKMetadataProvider.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Nullable
public static ZNRecord getZnRecord(@Nonnull ZkHelixPropertyStore<ZNRecord> propertyStore, @Nonnull String path) {
  Stat stat = new Stat();
  ZNRecord znRecord = propertyStore.get(path, stat, AccessOption.PERSISTENT);
  if (znRecord != null) {
    znRecord.setCreationTime(stat.getCtime());
    znRecord.setModifiedTime(stat.getMtime());
    znRecord.setVersion(stat.getVersion());
  }
  return znRecord;
}
 
Example 7
Source File: ZKMetadataProvider.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Nullable
public static OfflineSegmentZKMetadata getOfflineSegmentZKMetadata(
    @Nonnull ZkHelixPropertyStore<ZNRecord> propertyStore, @Nonnull String tableName, @Nonnull String segmentName) {
  String offlineTableName = TableNameBuilder.OFFLINE.tableNameWithType(tableName);
  ZNRecord znRecord = propertyStore
      .get(constructPropertyStorePathForSegment(offlineTableName, segmentName), null, AccessOption.PERSISTENT);
  if (znRecord == null) {
    return null;
  }
  return new OfflineSegmentZKMetadata(znRecord);
}
 
Example 8
Source File: ZKMetadataProvider.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Nullable
public static TableConfig getTableConfig(@Nonnull ZkHelixPropertyStore<ZNRecord> propertyStore,
    @Nonnull String tableNameWithType) {
  ZNRecord znRecord = propertyStore
      .get(constructPropertyStorePathForResourceConfig(tableNameWithType), null, AccessOption.PERSISTENT);
  if (znRecord == null) {
    return null;
  }
  try {
    return TableConfigUtils.fromZNRecord(znRecord);
  } catch (Exception e) {
    LOGGER.error("Caught exception while getting table configuration for table: {}", tableNameWithType, e);
    return null;
  }
}
 
Example 9
Source File: ZKMetadataProvider.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Nullable
public static Schema getSchema(@Nonnull ZkHelixPropertyStore<ZNRecord> propertyStore, @Nonnull String schemaName) {
  try {
    ZNRecord schemaZNRecord =
        propertyStore.get(constructPropertyStorePathForSchema(schemaName), null, AccessOption.PERSISTENT);
    if (schemaZNRecord == null) {
      return null;
    }
    return SchemaUtils.fromZNRecord(schemaZNRecord);
  } catch (Exception e) {
    LOGGER.error("Caught exception while getting schema: {}", schemaName, e);
    return null;
  }
}
 
Example 10
Source File: ZKMetadataProvider.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public static boolean getClusterTenantIsolationEnabled(ZkHelixPropertyStore<ZNRecord> propertyStore) {
  String controllerConfigPath = constructPropertyStorePathForControllerConfig(CLUSTER_TENANT_ISOLATION_ENABLED_KEY);
  if (propertyStore.exists(controllerConfigPath, AccessOption.PERSISTENT)) {
    ZNRecord znRecord = propertyStore.get(controllerConfigPath, null, AccessOption.PERSISTENT);
    if (znRecord.getSimpleFields().containsKey(CLUSTER_TENANT_ISOLATION_ENABLED_KEY)) {
      return znRecord.getBooleanField(CLUSTER_TENANT_ISOLATION_ENABLED_KEY, true);
    } else {
      return true;
    }
  } else {
    return true;
  }
}