private void recordAccess(AccessType lineageType, AccessType auditType) { if (!lineageRecorded[lineageType.ordinal()]) { accessRecorder.recordLineage(lineageType); lineageRecorded[lineageType.ordinal()] = true; } if (!auditRecorded[auditType.ordinal()]) { accessRecorder.emitAudit(auditType); auditRecorded[auditType.ordinal()] = true; } }
@Override public String apply(AccessType input) { return input.toString().toLowerCase(); } };
private DefaultDatasetRuntimeContext(AuthorizationEnforcer enforcer, DatasetAccessRecorder accessRecorder, Principal principal, DatasetId datasetId, @Nullable Class<? extends Annotation> constructorDefaultAnnotation) { this.enforcer = enforcer; this.accessRecorder = accessRecorder; this.principal = principal; this.datasetId = datasetId; this.constructorDefaultAnnotation = constructorDefaultAnnotation; this.lineageRecorded = new boolean[AccessType.values().length]; this.auditRecorded = new boolean[AccessType.values().length]; }
private void addDataKey(MDSKey.Builder builder, ProgramRunId run, AccessType accessType, @Nullable NamespacedEntityId component) { long invertedStartTime = getInvertedStartTime(run); builder.add(invertedStartTime); addProgram(builder, run.getParent()); builder.add(run.getEntityName()); builder.add(accessType.getType()); addComponent(builder, component); }
@Override public int hashCode() { return 31 * key.hashCode() + key.getAccessType().hashCode(); } }
private Relation toRelation(Row row) { Map<Character, EntityId> rowInfo = new HashMap<>(4); MDSKey.Splitter splitter = new MDSKey(row.getRow()).split(); char marker = (char) splitter.getInt(); LOG.trace("Got marker {}", marker); EntityId id1 = toEntityId(splitter, marker); LOG.trace("Got id1 {}", id1); rowInfo.put(marker, id1); splitter.skipLong(); // inverted time - not required for relation marker = (char) splitter.getInt(); LOG.trace("Got marker {}", marker); EntityId id2 = toEntityId(splitter, marker); LOG.trace("Got id2 {}", id1); rowInfo.put(marker, id2); RunId runId = RunIds.fromString(splitter.getString()); LOG.trace("Got runId {}", runId); AccessType accessType = AccessType.fromType((char) splitter.getInt()); LOG.trace("Got access type {}", accessType); DatasetId datasetInstance = (DatasetId) rowInfo.get(DATASET_MARKER); LOG.trace("Got datasetInstance {}", datasetInstance); ProgramId program = (ProgramId) rowInfo.get(PROGRAM_MARKER); LOG.trace("Got program {}", program); NamespacedEntityId component = toComponent(splitter, program); LOG.trace("Got component {}", component); return new Relation(datasetInstance, program, accessType, runId, component == null ? Collections.emptySet() : Collections.singleton(component)); }
private void addDataKey(MDSKey.Builder builder, ProgramRunId run, AccessType accessType, @Nullable NamespacedEntityId component) { long invertedStartTime = getInvertedStartTime(run); builder.add(invertedStartTime); addProgram(builder, run.getParent()); builder.add(run.getEntityName()); builder.add(accessType.getType()); addComponent(builder, component); }
@Override public int hashCode() { return 31 * key.hashCode() + key.getAccessType().hashCode(); } }
AccessType accessType = AccessType.fromType((char) splitter.getInt()); LOG.trace("Got access type {}", accessType);
private byte[] getProgramKey(ProgramRunId run, DatasetId datasetInstance, AccessType accessType, @Nullable NamespacedEntityId component) { long invertedStartTime = getInvertedStartTime(run); MDSKey.Builder builder = new MDSKey.Builder(); addProgram(builder, run.getParent()); builder.add(invertedStartTime); addDataset(builder, datasetInstance); builder.add(run.getEntityName()); builder.add(accessType.getType()); addComponent(builder, component); return builder.build().getKey(); }
private DefaultDatasetRuntimeContext(AuthorizationEnforcer enforcer, DatasetAccessRecorder accessRecorder, Principal principal, DatasetId datasetId, @Nullable Class<? extends Annotation> constructorDefaultAnnotation) { this.enforcer = enforcer; this.accessRecorder = accessRecorder; this.principal = principal; this.datasetId = datasetId; this.constructorDefaultAnnotation = constructorDefaultAnnotation; this.lineageRecorded = new boolean[AccessType.values().length]; this.auditRecorded = new boolean[AccessType.values().length]; }
@Override public String apply(AccessType input) { return input.toString().toLowerCase(); } };
private void recordAccess(AccessType lineageType, AccessType auditType) { if (!lineageRecorded[lineageType.ordinal()]) { accessRecorder.recordLineage(lineageType); lineageRecorded[lineageType.ordinal()] = true; } if (!auditRecorded[auditType.ordinal()]) { accessRecorder.emitAudit(auditType); auditRecorded[auditType.ordinal()] = true; } }
private byte[] getProgramKey(ProgramRunId run, DatasetId datasetInstance, AccessType accessType, @Nullable NamespacedEntityId component) { long invertedStartTime = getInvertedStartTime(run); MDSKey.Builder builder = new MDSKey.Builder(); addProgram(builder, run.getParent()); builder.add(invertedStartTime); addDataset(builder, datasetInstance); builder.add(run.getEntityName()); builder.add(accessType.getType()); addComponent(builder, component); return builder.build().getKey(); }
/** * Discard a dataset when it is known that no transaction is going on. * * @param dataset this is an Object because we need to pass in TransactionAware or Dataset */ private void discardSafely(Object dataset) { // iterates over all datasets but we do not expect this map to become large Set<AccessType> accessTypes = EnumSet.allOf(AccessType.class); for (Map.Entry<AccessAwareDatasetCacheKey, Dataset> entry : datasetCache.asMap().entrySet()) { if (dataset == entry.getValue()) { datasetCache.invalidate(entry.getKey()); // Make sure all unique access type are removed from the cache before breaking // This will ensure all different cache entries that shares the same underlying dataset instance gets // invalidated accessTypes.remove(entry.getKey().getDatasetCacheKey().getAccessType()); if (accessTypes.isEmpty()) { return; } } } // CDAP-14326 check if at least one of the entries of the given dataset was invalidated from datasetCache. This // means dataset provided was acquired through this context. Hence return without logging any warning. if (accessTypes.size() < AccessType.values().length) { return; } // we can only hope that dataset.toString() is meaningful LOG.warn("Attempt to discard a dataset that was not acquired through this context: {}", dataset); }
private byte[] getProgramKey(ProgramRunId run, StreamId stream, AccessType accessType, @Nullable NamespacedEntityId component) { long invertedStartTime = getInvertedStartTime(run); MDSKey.Builder builder = new MDSKey.Builder(); addProgram(builder, run.getParent()); builder.add(invertedStartTime); addStream(builder, stream); builder.add(run.getEntityName()); builder.add(accessType.getType()); addComponent(builder, component); return builder.build().getKey(); }
/** * Discard a dataset when it is known that no transaction is going on. * * @param dataset this is an Object because we need to pass in TransactionAware or Dataset */ private void discardSafely(Object dataset) { // iterates over all datasets but we do not expect this map to become large Set<AccessType> accessTypes = EnumSet.allOf(AccessType.class); for (Map.Entry<AccessAwareDatasetCacheKey, Dataset> entry : datasetCache.asMap().entrySet()) { if (dataset == entry.getValue()) { datasetCache.invalidate(entry.getKey()); // Make sure all unique access type are removed from the cache before breaking // This will ensure all different cache entries that shares the same underlying dataset instance gets // invalidated accessTypes.remove(entry.getKey().getDatasetCacheKey().getAccessType()); if (accessTypes.isEmpty()) { return; } } } // CDAP-14326 check if at least one of the entries of the given dataset was invalidated from datasetCache. This // means dataset provided was acquired through this context. Hence return without logging any warning. if (accessTypes.size() < AccessType.values().length) { return; } // we can only hope that dataset.toString() is meaningful LOG.warn("Attempt to discard a dataset that was not acquired through this context: {}", dataset); }