Search in sources :

Example 1 with RetentionStrategy

use of com.linkedin.pinot.controller.helix.core.retention.strategy.RetentionStrategy in project pinot by linkedin.

the class RetentionManager method scanSegmentMetadataAndPurge.

private void scanSegmentMetadataAndPurge() {
    for (String tableName : _segmentMetadataMap.keySet()) {
        List<SegmentZKMetadata> segmentZKMetadataList = _segmentMetadataMap.get(tableName);
        List<String> segmentsToDelete = new ArrayList<>(128);
        IdealState idealState = null;
        try {
            if (TableNameBuilder.getTableTypeFromTableName(tableName).equals(TableType.REALTIME)) {
                idealState = HelixHelper.getTableIdealState(_pinotHelixResourceManager.getHelixZkManager(), tableName);
            }
        } catch (Exception e) {
            LOGGER.warn("Could not get idealstate for {}", tableName, e);
        // Ignore, worst case we have some old inactive segments in place.
        }
        for (SegmentZKMetadata segmentZKMetadata : segmentZKMetadataList) {
            RetentionStrategy deletionStrategy;
            deletionStrategy = _tableDeletionStrategy.get(tableName);
            if (deletionStrategy == null) {
                LOGGER.info("No Retention strategy found for segment: {}", segmentZKMetadata.getSegmentName());
                continue;
            }
            if (segmentZKMetadata instanceof RealtimeSegmentZKMetadata) {
                final RealtimeSegmentZKMetadata realtimeSegmentZKMetadata = (RealtimeSegmentZKMetadata) segmentZKMetadata;
                if (realtimeSegmentZKMetadata.getStatus() == Status.IN_PROGRESS) {
                    final String segmentId = realtimeSegmentZKMetadata.getSegmentName();
                    if (SegmentName.isHighLevelConsumerSegmentName(segmentId)) {
                        continue;
                    }
                    // auto-create LLC segments.
                    if (shouldDeleteInProgressLLCSegment(segmentId, idealState, realtimeSegmentZKMetadata)) {
                        segmentsToDelete.add(segmentId);
                    }
                    continue;
                }
            }
            if (deletionStrategy.isPurgeable(segmentZKMetadata)) {
                LOGGER.info("Marking segment to delete: {}", segmentZKMetadata.getSegmentName());
                segmentsToDelete.add(segmentZKMetadata.getSegmentName());
            }
        }
        if (segmentsToDelete.size() > 0) {
            LOGGER.info("Trying to delete {} segments for table {}", segmentsToDelete.size(), tableName);
            _pinotHelixResourceManager.deleteSegments(tableName, segmentsToDelete);
        }
    }
}
Also used : SegmentZKMetadata(com.linkedin.pinot.common.metadata.segment.SegmentZKMetadata) RealtimeSegmentZKMetadata(com.linkedin.pinot.common.metadata.segment.RealtimeSegmentZKMetadata) OfflineSegmentZKMetadata(com.linkedin.pinot.common.metadata.segment.OfflineSegmentZKMetadata) RealtimeSegmentZKMetadata(com.linkedin.pinot.common.metadata.segment.RealtimeSegmentZKMetadata) TimeRetentionStrategy(com.linkedin.pinot.controller.helix.core.retention.strategy.TimeRetentionStrategy) RetentionStrategy(com.linkedin.pinot.controller.helix.core.retention.strategy.RetentionStrategy) ArrayList(java.util.ArrayList) IdealState(org.apache.helix.model.IdealState)

Aggregations

OfflineSegmentZKMetadata (com.linkedin.pinot.common.metadata.segment.OfflineSegmentZKMetadata)1 RealtimeSegmentZKMetadata (com.linkedin.pinot.common.metadata.segment.RealtimeSegmentZKMetadata)1 SegmentZKMetadata (com.linkedin.pinot.common.metadata.segment.SegmentZKMetadata)1 RetentionStrategy (com.linkedin.pinot.controller.helix.core.retention.strategy.RetentionStrategy)1 TimeRetentionStrategy (com.linkedin.pinot.controller.helix.core.retention.strategy.TimeRetentionStrategy)1 ArrayList (java.util.ArrayList)1 IdealState (org.apache.helix.model.IdealState)1