@Override public int getApproxSize() { return super.getApproxSize() + 4 + documentId.toString().length(); }
public int getSerializedSize() { int size = 0; if (docId != null) { size += Utf8.byteCount(docId.toString()) + 1; } size += GlobalId.LENGTH; size += 8; size += 1; return size; }
@Override public int getApproxSize() { return super.getApproxSize() + 4 + remove.getId().toString().length(); }
/** * Utility method to easily serialize a single document ID as a remove * operation. * * @param docId * the document to remove or which has been removed * @return a document remove operation serialised as UTF-8 encoded JSON for * the input document ID */ public static byte[] documentRemove(@NonNull DocumentId docId) { ByteArrayOutputStream out = new ByteArrayOutputStream(); try { JsonGenerator throwAway = jsonFactory.createGenerator(out); throwAway.writeStartObject(); throwAway.writeStringField(REMOVE, docId.toString()); throwAway.writeEndObject(); throwAway.close(); } catch (IOException e) { // Under normal circumstances, nothing here will be triggered throw new RuntimeException(e); } return out.toByteArray(); }
public ProxyDocumentUpdate(DocumentUpdate docUpd, Map<String, String> fieldMap) { super(docUpd.getType(), docUpd.getId().toString()+"-schemamappedupdate"); this.docU=docUpd; this.fieldMap=fieldMap; }
@Override public void write(FieldBase field, Document value) { try { fieldNameIfNotNull(generator, field); generator.writeStartObject(); // this makes it impossible to refeed directly, not sure what's correct // perhaps just change to "put"? generator.writeStringField("id", value.getId().toString()); generator.writeObjectFieldStart(FIELDS); Iterator<Map.Entry<Field, FieldValue>> i = value.iterator(); while (i.hasNext()) { Map.Entry<Field, FieldValue> entry = i.next(); entry.getValue().serialize(entry.getKey(), this); } generator.writeEndObject(); generator.writeEndObject(); generator.flush(); } catch (IOException e) { throw new RuntimeException(e); } }
boolean containsRemove(List<IterateResult> chunks, String docId) { for (IterateResult i : chunks) { for (DocEntry e : i.getEntries()) { if (e.getType() == DocEntry.Type.REMOVE_ENTRY && e.getDocumentId() != null && e.getDocumentId().toString().equals(docId)) { return true; } } } return false; }
@Override public void write(DocumentUpdate update) { wrapIOException(() -> { generator.writeStartObject(); generator.writeStringField("update", update.getId().toString()); if (update.getCondition().isPresent()) { generator.writeStringField("condition", update.getCondition().getSelection()); } Optional<Boolean> createIfNotExistent = update.getOptionalCreateIfNonExistent(); if (createIfNotExistent.isPresent()) { generator.writeBooleanField("create", createIfNotExistent.get()); } generator.writeObjectFieldStart("fields"); for (FieldUpdate up : update.fieldUpdates()) { up.serialize(this); } update.fieldPathUpdates().stream() .collect(Collectors.groupingBy(FieldPathUpdate::getFieldPath)) .forEach((fieldPath, fieldPathUpdates) -> wrapIOException(() -> write(fieldPath, fieldPathUpdates, generator))); generator.writeEndObject(); generator.writeEndObject(); generator.flush(); }); }
field = new FieldBase(document.getId().toString());
static DocumentOperationMessageV3 newUpdateMessage(VespaXMLFeedReader.Operation op, String operationId) { DocumentUpdate update = op.getDocumentUpdate(); update.setCondition(op.getCondition()); Message msg = new UpdateDocumentMessage(update); String id = (operationId == null) ? update.getId().toString() : operationId; return new DocumentOperationMessageV3(id, msg); }
void testIterateExplicitTimestampSubset(PersistenceProvider spi) throws Exception { Bucket b = new Bucket((short)0, new BucketId(8, 0x1)); spi.createBucket(b); List<DocEntry> docsToVisit = new ArrayList<DocEntry>(); Set<Long> timestampsToVisit = new TreeSet<Long>(); List<String> removes = new ArrayList<String>(); for (int i = 0; i < 99; i++) { long timestamp = 1000 + i; Document doc = testDocMan.createRandomDocumentAtLocation(1, timestamp, 110, 110); spi.put(b, timestamp, doc); if (timestamp % 3 == 0) { docsToVisit.add(new DocEntry(timestamp, doc)); timestampsToVisit.add(timestamp); } } assertTrue(spi.remove(b, 2000, docsToVisit.get(0).getDocument().getId()).wasFound()); spi.flush(b); timestampsToVisit.add(2000l); removes.add(docsToVisit.get(0).getDocument().getId().toString()); timestampsToVisit.remove(docsToVisit.get(0).getTimestamp()); docsToVisit.remove(docsToVisit.get(0)); // When selecting a timestamp subset, we should ignore IncludedVersions, and return all matches regardless. CreateIteratorResult iter = spi.createIterator(b, new AllFields(), new Selection(timestampsToVisit), PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_ONLY); List<IterateResult> chunks = doIterate(spi, iter.getIteratorId(), 2048, 0); verifyDocs(docsToVisit, chunks, removes); spi.destroyIterator(iter.getIteratorId()); }
static DocumentOperationMessageV3 newPutMessage(VespaXMLFeedReader.Operation op, String operationId) { DocumentPut put = new DocumentPut(op.getDocument()); put.setCondition(op.getCondition()); Message msg = new PutDocumentMessage(put); String id = (operationId == null) ? put.getId().toString() : operationId; return new DocumentOperationMessageV3(id, msg); }
void testIterationRequiringDocumentIdOnlyMatching(PersistenceProvider spi) throws Exception { Bucket b = new Bucket((short)0, new BucketId(8, 0x1)); spi.createBucket(b); feedDocs(spi, b, 100, 100, 100); DocumentId removedId = new DocumentId("userdoc:blarg:1:unknowndoc"); // Document does not already exist, remove should create a // remove entry for it regardless. assertFalse(spi.remove(b, 2000, removedId).wasFound()); spi.flush(b); CreateIteratorResult iter = spi.createIterator(b, new AllFields(), new Selection("id == '" + removedId.toString() + "'", 0, Long.MAX_VALUE), PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_OR_REMOVE); List<IterateResult> chunks = doIterate(spi, iter.getIteratorId(), 4096, 0); List<String> removes = new ArrayList<String>(); List<DocEntry> docs = new ArrayList<DocEntry>(); removes.add(removedId.toString()); verifyDocs(docs, chunks, removes); spi.destroyIterator(iter.getIteratorId()); }
static DocumentOperationMessageV3 newRemoveMessage(VespaXMLFeedReader.Operation op, String operationId) { DocumentRemove remove = new DocumentRemove(op.getRemove()); remove.setCondition(op.getCondition()); Message msg = new RemoveDocumentMessage(remove); String id = (operationId == null) ? remove.getId().toString() : operationId; return new DocumentOperationMessageV3(id, msg); }
return id.toString(); } else if (field.equalsIgnoreCase("scheme")) { return id.getScheme().getType().toString();
removedDocs.add(docs.get(i).getDocument().getId().toString()); assertTrue(spi.remove(b, 2000 + i, docs.get(i).getDocument().getId()).wasFound()); } else {
docIds[i] = entry.getDocumentId().toString(); } else { docIds[i] = "";