@Override public void resetId(ILSMComponentId componentId, boolean force) throws HyracksDataException { if (!force && this.componentId != null && this.componentId.compareTo(componentId) != IdCompareResult.LESS_THAN) { throw new IllegalStateException( this + " receives illegal id. Old id " + this.componentId + ", new id " + componentId); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Component Id was reset from " + this.componentId + " to " + componentId); } this.componentId = componentId; if (componentId != null) { LSMComponentIdUtils.persist(this.componentId, metadata); } }
@Override public ILSMComponentId getId() throws HyracksDataException { if (componentId != null) { return componentId; } synchronized (this) { if (componentId == null) { componentId = LSMComponentIdUtils.readFrom(metadata, buffer); } } if (componentId.missing()) { // For normal datasets, componentId shouldn't be missing, since otherwise it'll be a bug. // However, we cannot throw an exception here to be compatible with legacy datasets. // In this case, the disk component would always get a garbage Id [-1, -1], which makes the // component Id-based optimization useless but still correct. LOGGER.warn("Component Id not found from disk component metadata"); } return componentId; }
/** * A helper method to ensure disk components have proper Ids (non-decreasing) * We may get rid of this method once component Id is stablized * * @throws HyracksDataException */ private void validateComponentIds() throws HyracksDataException { for (int i = 0; i < diskComponents.size() - 1; i++) { ILSMComponentId id1 = diskComponents.get(i).getId(); ILSMComponentId id2 = diskComponents.get(i + 1).getId(); IdCompareResult cmp = id1.compareTo(id2); if (cmp != IdCompareResult.UNKNOWN && cmp != IdCompareResult.GREATER_THAN) { throw new IllegalStateException( "found non-decreasing component ids (" + id1 + " -> " + id2 + ") on index " + this); } } }
@Override public IdCompareResult compareTo(ILSMComponentId id) { if (this.missing() || id == null || id.missing()) { return IdCompareResult.UNKNOWN; } LSMComponentId componentId = (LSMComponentId) id; if (this.getMinId() > componentId.getMaxId()) { return IdCompareResult.GREATER_THAN; } else if (this.getMaxId() < componentId.getMinId()) { return IdCompareResult.LESS_THAN; } else if (this.getMinId() <= componentId.getMinId() && this.getMaxId() >= componentId.getMaxId()) { return IdCompareResult.INCLUDE; } else { return IdCompareResult.INTERSECT; } }
for (ILSMDiskComponent component : immutableComponents) { ILSMComponentId id = component.getId(); IdCompareResult cmp = targetId.compareTo(id); if (cmp == IdCompareResult.INCLUDE) { mergableComponents.add(component);
ILSMDiskComponent diskComponent = index.getDiskComponents().get(0); ILSMComponentId maxDiskComponentId = diskComponent.getId(); if (maxDiskComponentId.compareTo(id) != IdCompareResult.LESS_THAN) { throw new IllegalStateException("Illegal state of component Id. Max disk component Id " + maxDiskComponentId + " should be less than redo flush component Id " + id);