Skip to content

Commit 42840b2

Browse files
author
Ryan Dew
committed
MLE-29883 (GH #1938) Include document version in bulk reads
1 parent 0c45494 commit 42840b2

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

marklogic-client-api/src/main/java/com/marklogic/client/impl/OkHttpServices.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,17 @@ static private Format getHeaderFormat(BodyPart part) {
17131713
return null;
17141714
}
17151715

1716+
// Bulk multi-document reads carry the version as a "versionId" param on Content-Disposition, not as an ETag header.
1717+
static private long getHeaderVersion(BodyPart part) {
1718+
String contentDisposition = getHeader(part, HEADER_CONTENT_DISPOSITION);
1719+
String versionRegex = ".* versionId=([0-9]+).*";
1720+
if (contentDisposition != null && contentDisposition.matches(versionRegex)) {
1721+
String version = contentDisposition.replaceFirst("^.*" + versionRegex + ".*$", "$1");
1722+
return Utilities.parseLong(version, DocumentDescriptor.UNKNOWN_VERSION);
1723+
}
1724+
return DocumentDescriptor.UNKNOWN_VERSION;
1725+
}
1726+
17161727
static private void updateMimetype(ContentDescriptor descriptor,
17171728
Headers headers) {
17181729
updateMimetype(descriptor, getHeaderMimetype(headers.get(HEADER_CONTENT_TYPE)));
@@ -1837,10 +1848,6 @@ static private void updateVersion(DocumentDescriptor descriptor, Headers headers
18371848
updateVersion(descriptor, extractVersion(headers.get(HEADER_ETAG)));
18381849
}
18391850

1840-
static private void updateVersion(DocumentDescriptor descriptor, String header) {
1841-
updateVersion(descriptor, extractVersion(header));
1842-
}
1843-
18441851
static private void updateVersion(DocumentDescriptor descriptor, long version) {
18451852
descriptor.setVersion(version);
18461853
}
@@ -4436,6 +4443,7 @@ static class OkHttpResult {
44364443
private Format format;
44374444
private String mimetype;
44384445
private long length;
4446+
private long version = DocumentDescriptor.UNKNOWN_VERSION;
44394447

44404448
OkHttpResult(RequestLogger reqlog, BodyPart part) {
44414449
this.reqlog = reqlog;
@@ -4490,6 +4498,11 @@ public long getLength() {
44904498
return length;
44914499
}
44924500

4501+
public long getVersion() {
4502+
extractHeaders();
4503+
return version;
4504+
}
4505+
44934506
public String getHeader(String name) {
44944507
extractHeaders();
44954508
List<String> values = headers.get(name);
@@ -4515,6 +4528,7 @@ private void extractHeaders() {
45154528
mimetype = getHeaderMimetype(OkHttpServices.getHeader(part, HEADER_CONTENT_TYPE));
45164529
length = getHeaderLength(OkHttpServices.getHeader(part, HEADER_CONTENT_LENGTH));
45174530
uri = getHeaderUri(part);
4531+
version = getHeaderVersion(part);
45184532
extractedHeaders = true;
45194533
} catch (MessagingException e) {
45204534
throw new MarkLogicIOException(e);
@@ -4688,7 +4702,7 @@ public DocumentDescriptor getDescriptor() {
46884702
updateFormat(descriptor, getFormat());
46894703
updateMimetype(descriptor, getMimetype());
46904704
updateLength(descriptor, getLength());
4691-
updateVersion(descriptor, content.getHeader(HEADER_ETAG));
4705+
updateVersion(descriptor, content.getVersion());
46924706
return descriptor;
46934707
}
46944708

marklogic-client-api/src/test/java/com/marklogic/client/test/ConditionalDocumentTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
2+
* Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
33
*/
44
package com.marklogic.client.test;
55

@@ -192,21 +192,26 @@ public void testConditionalMultiple() {
192192

193193
XMLDocumentManager docMgr = Common.client.newXMLDocumentManager();
194194

195-
verifyDescriptors(docList, docMgr.read(docIds));
195+
verifyDescriptors(docList, docMgr.read(docIds), docMgr);
196196

197197
verifyDescriptors(
198198
docList,
199-
docMgr.search(new StructuredQueryBuilder().document(docIds), 1)
199+
docMgr.search(new StructuredQueryBuilder().document(docIds), 1),
200+
docMgr
200201
);
201202
}
202-
void verifyDescriptors(List<String> docList, DocumentPage page) {
203+
204+
void verifyDescriptors(List<String> docList, DocumentPage page, XMLDocumentManager docMgr) {
203205
for (DocumentRecord record: page) {
204206
DocumentDescriptor desc = record.getDescriptor();
205207
assertTrue( docList.contains(desc.getUri()));
206208
assertEquals( Format.XML, desc.getFormat());
207209
assertTrue( desc.getMimetype().startsWith("application/xml"));
208210
assertTrue( desc.getByteLength() >= 0);
209-
assertTrue( desc.getVersion() >= -1);
211+
// bulk read() should report the same version as exists() for each document
212+
assertNotEquals( DocumentDescriptor.UNKNOWN_VERSION, desc.getVersion());
213+
long existsVersion = docMgr.exists(record.getUri()).getVersion();
214+
assertEquals( existsVersion, desc.getVersion());
210215
}
211216
}
212217
}

0 commit comments

Comments
 (0)