use of javax.annotation.Nullable in project pinot by linkedin.
the class ZKMetadataProvider method getRealtimeSegmentZKMetadata.
@Nullable
public static RealtimeSegmentZKMetadata getRealtimeSegmentZKMetadata(ZkHelixPropertyStore<ZNRecord> propertyStore, String tableName, String segmentName) {
String realtimeTableName = TableNameBuilder.REALTIME_TABLE_NAME_BUILDER.forTable(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);
}
}
use of javax.annotation.Nullable in project pinot by linkedin.
the class SchemaUtils method getSchema.
/**
* Given host, port and schema name, send a http GET request to download the {@link Schema}.
*
* @return schema on success.
* <P><code>null</code> on failure.
*/
@Nullable
public static Schema getSchema(@Nonnull String host, int port, @Nonnull String schemaName) {
Preconditions.checkNotNull(host);
Preconditions.checkNotNull(schemaName);
try {
URL url = new URL("http", host, port, "/schemas/" + schemaName);
GetMethod httpGet = new GetMethod(url.toString());
try {
int responseCode = HTTP_CLIENT.executeMethod(httpGet);
String response = httpGet.getResponseBodyAsString();
if (responseCode >= 400) {
// File not find error code.
if (responseCode == 404) {
LOGGER.info("Cannot find schema: {} from host: {}, port: {}", schemaName, host, port);
} else {
LOGGER.warn("Got error response code: {}, response: {}", responseCode, response);
}
return null;
}
return Schema.fromString(response);
} finally {
httpGet.releaseConnection();
}
} catch (Exception e) {
LOGGER.error("Caught exception while getting the schema: {} from host: {}, port: {}", schemaName, host, port, e);
return null;
}
}
use of javax.annotation.Nullable in project pinot by linkedin.
the class PinotHelixResourceManager method getSchema.
/**
*
* @param schemaName
* @return
* @throws JsonParseException
* @throws JsonMappingException
* @throws IOException
*/
@Nullable
public Schema getSchema(String schemaName) throws JsonParseException, JsonMappingException, IOException {
PinotHelixPropertyStoreZnRecordProvider propertyStoreHelper = PinotHelixPropertyStoreZnRecordProvider.forSchema(_propertyStore);
ZNRecord record = propertyStoreHelper.get(schemaName);
return record != null ? SchemaUtils.fromZNRecord(record) : null;
}
use of javax.annotation.Nullable in project pinot by linkedin.
the class PinotHelixResourceManager method rebuildBrokerResourceFromHelixTags.
public PinotResourceManagerResponse rebuildBrokerResourceFromHelixTags(final String tableName) {
// Get the broker tag for this table
String brokerTag = null;
TenantConfig tenantConfig = null;
try {
final TableType tableType = TableNameBuilder.getTableTypeFromTableName(tableName);
AbstractTableConfig tableConfig;
if (tableType == TableType.OFFLINE) {
tableConfig = ZKMetadataProvider.getOfflineTableConfig(getPropertyStore(), tableName);
} else if (tableType == TableType.REALTIME) {
tableConfig = ZKMetadataProvider.getRealtimeTableConfig(getPropertyStore(), tableName);
} else {
return new PinotResourceManagerResponse("Table " + tableName + " does not have a table type", false);
}
if (tableConfig == null) {
return new PinotResourceManagerResponse("Table " + tableName + " does not exist", false);
}
tenantConfig = tableConfig.getTenantConfig();
} catch (Exception e) {
LOGGER.warn("Caught exception while getting tenant config for table {}", tableName, e);
return new PinotResourceManagerResponse("Failed to fetch broker tag for table " + tableName + " due to exception: " + e.getMessage(), false);
}
brokerTag = tenantConfig.getBroker();
// Look for all instances tagged with this broker tag
final Set<String> brokerInstances = getAllInstancesForBrokerTenant(brokerTag);
// If we add a new broker, we want to rebuild the broker resource.
HelixAdmin helixAdmin = getHelixAdmin();
String clusterName = getHelixClusterName();
IdealState brokerIdealState = HelixHelper.getBrokerIdealStates(helixAdmin, clusterName);
Set<String> idealStateBrokerInstances = brokerIdealState.getInstanceSet(tableName);
if (idealStateBrokerInstances.equals(brokerInstances)) {
return new PinotResourceManagerResponse("Broker resource is not rebuilt because ideal state is the same for table {} " + tableName, false);
}
// Reset ideal state with the instance list
try {
HelixHelper.updateIdealState(getHelixZkManager(), CommonConstants.Helix.BROKER_RESOURCE_INSTANCE, new Function<IdealState, IdealState>() {
@Nullable
@Override
public IdealState apply(@Nullable IdealState idealState) {
Map<String, String> instanceStateMap = idealState.getInstanceStateMap(tableName);
if (instanceStateMap != null) {
instanceStateMap.clear();
}
for (String brokerInstance : brokerInstances) {
idealState.setPartitionState(tableName, brokerInstance, BrokerOnlineOfflineStateModel.ONLINE);
}
return idealState;
}
}, DEFAULT_RETRY_POLICY);
LOGGER.info("Successfully rebuilt brokerResource for table {}", tableName);
return new PinotResourceManagerResponse("Rebuilt brokerResource for table " + tableName, true);
} catch (Exception e) {
LOGGER.warn("Caught exception while rebuilding broker resource from Helix tags for table {}", e, tableName);
return new PinotResourceManagerResponse("Failed to rebuild brokerResource for table " + tableName + " due to exception: " + e.getMessage(), false);
}
}
use of javax.annotation.Nullable in project pinot by linkedin.
the class TableSizeReader method getTableSizeDetails.
/**
* Get the table size.
* This one polls all servers in parallel for segment sizes. In the response,
* reported size indicates actual sizes collected from servers. For errors,
* we use the size of largest segment as an estimate.
* Returns null if the table is not found.
* @param tableName
* @param timeoutMsec
* @return
*/
@Nullable
public TableSizeDetails getTableSizeDetails(@Nonnull String tableName, @Nonnegative int timeoutMsec) {
Preconditions.checkNotNull(tableName, "Table name should not be null");
Preconditions.checkArgument(timeoutMsec > 0, "Timeout value must be greater than 0");
boolean hasRealtimeTable = false;
boolean hasOfflineTable = false;
CommonConstants.Helix.TableType tableType = TableNameBuilder.getTableTypeFromTableName(tableName);
if (tableType != null) {
hasRealtimeTable = tableType == CommonConstants.Helix.TableType.REALTIME;
hasOfflineTable = tableType == CommonConstants.Helix.TableType.OFFLINE;
} else {
hasRealtimeTable = helixResourceManager.hasRealtimeTable(tableName);
hasOfflineTable = helixResourceManager.hasOfflineTable(tableName);
}
if (!hasOfflineTable && !hasRealtimeTable) {
return null;
}
TableSizeDetails tableSizeDetails = new TableSizeDetails(tableName);
if (hasRealtimeTable) {
String realtimeTableName = new TableNameBuilder(CommonConstants.Helix.TableType.REALTIME).forTable(tableName);
tableSizeDetails.realtimeSegments = getTableSubtypeSize(realtimeTableName, timeoutMsec);
tableSizeDetails.reportedSizeInBytes += tableSizeDetails.realtimeSegments.reportedSizeInBytes;
tableSizeDetails.estimatedSizeInBytes += tableSizeDetails.realtimeSegments.estimatedSizeInBytes;
}
if (hasOfflineTable) {
String offlineTableName = new TableNameBuilder(CommonConstants.Helix.TableType.OFFLINE).forTable(tableName);
tableSizeDetails.offlineSegments = getTableSubtypeSize(offlineTableName, timeoutMsec);
tableSizeDetails.reportedSizeInBytes += tableSizeDetails.offlineSegments.reportedSizeInBytes;
tableSizeDetails.estimatedSizeInBytes += tableSizeDetails.offlineSegments.estimatedSizeInBytes;
}
return tableSizeDetails;
}
Aggregations