Search in sources :

Example 31 with Nullable

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);
    }
}
Also used : RealtimeSegmentZKMetadata(com.linkedin.pinot.common.metadata.segment.RealtimeSegmentZKMetadata) LLCRealtimeSegmentZKMetadata(com.linkedin.pinot.common.metadata.segment.LLCRealtimeSegmentZKMetadata) LLCRealtimeSegmentZKMetadata(com.linkedin.pinot.common.metadata.segment.LLCRealtimeSegmentZKMetadata) ZNRecord(org.apache.helix.ZNRecord) Nullable(javax.annotation.Nullable)

Example 32 with Nullable

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;
    }
}
Also used : GetMethod(org.apache.commons.httpclient.methods.GetMethod) URL(java.net.URL) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Example 33 with Nullable

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;
}
Also used : PinotHelixPropertyStoreZnRecordProvider(com.linkedin.pinot.common.utils.helix.PinotHelixPropertyStoreZnRecordProvider) ZNRecord(org.apache.helix.ZNRecord) Nullable(javax.annotation.Nullable)

Example 34 with Nullable

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);
    }
}
Also used : TableType(com.linkedin.pinot.common.utils.CommonConstants.Helix.TableType) HelixAdmin(org.apache.helix.HelixAdmin) JsonProcessingException(org.codehaus.jackson.JsonProcessingException) JSONException(org.json.JSONException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) IdealState(org.apache.helix.model.IdealState) TenantConfig(com.linkedin.pinot.common.config.TenantConfig) AbstractTableConfig(com.linkedin.pinot.common.config.AbstractTableConfig) Map(java.util.Map) BiMap(com.google.common.collect.BiMap) HashMap(java.util.HashMap) HashBiMap(com.google.common.collect.HashBiMap) Nullable(javax.annotation.Nullable)

Example 35 with Nullable

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;
}
Also used : TableNameBuilder(com.linkedin.pinot.common.config.TableNameBuilder) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)3188 List (java.util.List)363 IOException (java.io.IOException)307 Map (java.util.Map)294 ArrayList (java.util.ArrayList)284 Nonnull (javax.annotation.Nonnull)264 File (java.io.File)225 Collectors (java.util.stream.Collectors)175 Arrays (java.util.Arrays)165 HashMap (java.util.HashMap)161 Test (org.junit.Test)137 Layer (com.simiacryptus.mindseye.lang.Layer)116 Tensor (com.simiacryptus.mindseye.lang.Tensor)116 ItemStack (net.minecraft.item.ItemStack)115 Logger (org.slf4j.Logger)113 LoggerFactory (org.slf4j.LoggerFactory)113 ImmutableList (com.google.common.collect.ImmutableList)111 Set (java.util.Set)107 Result (com.simiacryptus.mindseye.lang.Result)104 Function (com.google.common.base.Function)100