public List<ObjectId> toRefs(JsonNode refsNode) { if (refsNode != null) { try { return mapper.convertValue(refsNode, new TypeReference<List<ObjectId>>() { }); } catch (Exception ex) { LOG.debug("Failed to get objectIds: " + refsNode, ex); } } return null; }
@Override public void uncaughtException(Thread t, Throwable e) { LOG.error("Thread " + t.getName() + " threw uncaught exception", e); } })
private void traceLogging(Set<ObjectId> ids, Set<ObjectId> existence, ViewFieldChange fieldChange) { if (LOG.isTraceEnabled()) { StringBuilder msg = new StringBuilder().append(" existence:"); String sep = ""; for (ObjectId id : ids) { msg.append(sep); msg.append(id).append(existence.contains(id) ? " exists" : " does not exist"); sep = ","; } msg.append(" change:").append(fieldChange); if (LOG.isTraceEnabled()) { LOG.trace("WRITE BLOCKED DUE TO LACK OF EXISTANCE:" + msg.toString()); } } } }
@Override public void run() { try { if (requests.size() > 1) { LOG.debug("Request aggregation size: {}", requests.size()); } referenceStore.multiStreamRefs(requests); } catch (Exception ex) { LOG.warn("Failed to process request:" + requests, ex); for (RefStreamRequestContext request : requests) { request.failure(ex); } } } });
@Override public void process(WrittenEventContext batchContext, TenantIdAndCentricId tenantIdAndCentricId, WrittenEvent writtenEvent, long threadTimestamp) throws Exception { if (valueTraversers != null && !valueTraversers.isEmpty()) { LOG.startTimer("values"); try { processValues(batchContext, tenantIdAndCentricId, writtenEvent, threadTimestamp); } finally { LOG.stopTimer("values"); } } LOG.startTimer("refs"); try { processRefs(batchContext, tenantIdAndCentricId, writtenEvent, threadTimestamp); } finally { LOG.stopTimer("refs"); } }
@Override public ColumnValueAndTimestamp<ObjectId, byte[], Long> callback(ColumnValueAndTimestamp<ObjectId, byte[], Long> v) throws Exception { if (v == null) { if (!batch.isEmpty()) { refStreamQueue.put(batch); } refStreamQueue.put(NULL); } else { ReferenceWithTimestamp referenceWithTimestamp = new ReferenceWithTimestamp(v.getColumn(), referringFieldName, v.getTimestamp()); batch.add(referenceWithTimestamp); if (batch.size() > MAX_FAN_OUT_BEFORE_WARN) { LOG.warn("TODO: streamBackRefs reference fan-out is exceeding comfort level. We need to break scans into batched scans."); } } return v; }
public Id toId(JsonNode jsonNode) { if (jsonNode != null) { try { return mapper.convertValue(jsonNode, Id.class); } catch (Exception ex) { LOG.debug("Failed to get id: " + jsonNode, ex); } } return null; }
@Override public void removeObjectId(List<ExistenceUpdate> existenceUpdates) { List<TenantRowColumnTimestampRemove<TenantIdAndCentricId, ObjectId, String>> batch = new ArrayList<>(); for (ExistenceUpdate existenceUpdate : existenceUpdates) { batch.add(new TenantRowColumnTimestampRemove<>(existenceUpdate.tenantId, existenceUpdate.objectId, EXISTS, new ConstantTimestamper(existenceUpdate.timestamp))); if (LOG.isTraceEnabled()) { LOG.trace("Object REMOVED:{} time:{}", new Object[]{existenceUpdate.objectId, existenceUpdate.timestamp}); } } updatedStore.multiRowsMultiRemove(batch); }
@Override public void uncaughtException(Thread t, Throwable e) { LOG.error("Thread " + t.getName() + " threw uncaught exception", e); } })
@Override public void stream(ViewDescriptor viewDescriptor, ColumnValueAndTimestamp<ImmutableByteArray, ViewValue, Long> value) { if (value != null && value.getTimestamp() < System.currentTimeMillis() - removeUndeclaredFieldsAfterNMillis) { try { ImmutableByteArray rowKey = viewValueStore.rowKey(viewDescriptor.getViewId()); viewValueStore.remove(viewDescriptor.getTenantIdAndCentricId(), rowKey, value.getColumn(), value.getTimestamp() + 1); } catch (IOException x) { LOG.warn("Failed trying to cleanup stale fields for:{} ", viewDescriptor); } } } };
public ObjectId toRef(JsonNode refNode) { if (refNode != null) { try { return mapper.convertValue(refNode, ObjectId.class); } catch (Exception ex) { LOG.debug("Failed to get objectId: " + refNode, ex); } } return null; }
@Override public void run() { try { tenantViewsProvider.reloadModels(); } catch (Exception x) { LOG.error("Scheduled reloading of view model failed. ", x); } } }, config.getPollForModelChangesEveryNSeconds(), config.getPollForModelChangesEveryNSeconds(), TimeUnit.SECONDS);
private EventVerb getActivityVerb(ObjectNode objectNode, String fieldName) { JsonNode got = objectNode.get(fieldName); if (got == null || got.isNull()) { return null; } try { return mapper.convertValue(got, EventVerb.class); } catch (Exception ex) { LOG.debug("Failed to get activity verb for field " + fieldName + ": " + objectNode, ex); return null; } }
@Override public void run() { try { processingStats.logStats(); } catch (Exception x) { LOG.error("Issue with logging stats. ", x); } } }, 60, 60, TimeUnit.SECONDS);
public long getEventId(ObjectNode eventNode) { JsonNode got = eventNode.get(ReservedFields.EVENT_ID); if (got == null || got.isNull()) { return 0L; } try { return got.longValue(); } catch (Exception ex) { LOG.debug("Failed to get eventId: " + eventNode, ex); return 0L; } }
public TenantId getTenantId(ObjectNode eventNode) { try { JsonNode got = eventNode.get(ReservedFields.TENANT_ID); if (got == null || got.isNull()) { return null; } return new TenantId(got.textValue()); } catch (Exception ex) { LOG.debug("Failed to get tenantId: " + eventNode, ex); return null; } }
private Id getId(ObjectNode objectNode, String fieldName) { JsonNode got = objectNode.get(fieldName); if (got == null || got.isNull()) { return null; } try { return new Id(got.textValue()); } catch (Exception ex) { LOG.debug("Failed to get objectId for field " + fieldName + ": " + objectNode, ex); return null; } }
public Id getInstanceId(ObjectNode eventNode, String className) { JsonNode got = eventNode.get(className); if (got == null || got.isNull() || !got.isObject()) { return null; } ObjectNode instanceNode = (ObjectNode) got; got = instanceNode.get(ReservedFields.INSTANCE_ID); if (got == null || got.isNull()) { return null; } try { return new Id(got.textValue()); } catch (Exception ex) { LOG.debug("Failed to get instanceId for className '" + className + "': " + eventNode, ex); return null; } }
public void remove(TenantIdAndCentricId tenantIdAndCentricId, List<ViewWriteFieldChange> removes) throws IOException { MultiRemove<ImmutableByteArray, ImmutableByteArray> rawRemoves = new MultiRemove<>(); for (ViewWriteFieldChange change : removes) { rawRemoves.add(rowKey(change.getViewObjectId()), columnKey(change.getModelPathIdHashcode(), change.getModelPathInstanceIds()), new ConstantTimestamper(change.getTimestamp())); LOG.debug("VVS:REMOVED {}", change); } List<RowColumnTimestampRemove<ImmutableByteArray, ImmutableByteArray>> took = rawRemoves.take(); viewValueStore.multiRowsMultiRemove(tenantIdAndCentricId, took); }
public void add(TenantIdAndCentricId tenantIdAndCentricId, List<ViewWriteFieldChange> adds) throws IOException { MultiAdd<ImmutableByteArray, ImmutableByteArray, ViewValue> rawAdds = new MultiAdd<>(); for (ViewWriteFieldChange change : adds) { rawAdds.add(rowKey(change.getViewObjectId()), columnKey(change.getModelPathIdHashcode(), change.getModelPathInstanceIds()), change.getValue(), new ConstantTimestamper(change.getTimestamp())); LOG.debug("VVS:ADD {}", change); } List<RowColumValueTimestampAdd<ImmutableByteArray, ImmutableByteArray, ViewValue>> took = rawAdds.take(); viewValueStore.multiRowsMultiAdd(tenantIdAndCentricId, took); }