-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Introduce a bulk format that uses a prefix length #135506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
c0cd23c
5fe2f98
fd1d01a
9a76c9c
b457285
a5b22bf
e1ac118
5ae85ef
f48ff2b
60c2877
fc02961
5759b1e
e7c6ebe
eb50ecb
476df29
fc7513a
e9998e6
1cb3c97
bb7db43
71b1081
23d9f65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 135506 | ||
summary: "[Draft] Introduce a bulk format that uses a prefix length" | ||
area: Store | ||
type: enhancement | ||
issues: [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
import org.elasticsearch.action.bulk.IncrementalBulkService; | ||
import org.elasticsearch.action.support.ActiveShardCount; | ||
import org.elasticsearch.client.internal.node.NodeClient; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.bytes.BytesReference; | ||
import org.elasticsearch.common.bytes.CompositeBytesReference; | ||
import org.elasticsearch.common.bytes.ReleasableBytesReference; | ||
|
@@ -41,6 +42,7 @@ | |
import java.util.ArrayDeque; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Supplier; | ||
|
@@ -62,6 +64,28 @@ public class RestBulkAction extends BaseRestHandler { | |
|
||
public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in bulk requests is deprecated."; | ||
public static final String FAILURE_STORE_STATUS_CAPABILITY = "failure_store_status"; | ||
|
||
private static final String BULK_FORMAT_HEADER = "Bulk-Format"; | ||
|
||
|
||
public enum BulkFormat { | ||
PREFIX_LENGTH, | ||
MARKER_SUFFIX; | ||
|
||
static BulkFormat parse(String bulkFormat) { | ||
if (Strings.hasText(bulkFormat)) { | ||
if ("marker-suffix".equalsIgnoreCase(bulkFormat)) { | ||
return MARKER_SUFFIX; | ||
} else if ("prefix-length".equalsIgnoreCase(bulkFormat)) { | ||
return PREFIX_LENGTH; | ||
} else { | ||
throw new IllegalArgumentException("Unknown bulk format: " + bulkFormat); | ||
} | ||
} else { | ||
throw new IllegalArgumentException("Header [" + BULK_FORMAT_HEADER + "] cannot be empty."); | ||
} | ||
} | ||
} | ||
|
||
private final boolean allowExplicitIndex; | ||
private final IncrementalBulkService bulkHandler; | ||
private final IncrementalBulkService.Enabled incrementalEnabled; | ||
|
@@ -127,6 +151,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC | |
defaultListExecutedPipelines, | ||
allowExplicitIndex, | ||
request.getXContentType(), | ||
parseBulkFormatHeader(request.getHeaders()), | ||
request.getRestApiVersion() | ||
); | ||
} catch (Exception e) { | ||
|
@@ -149,6 +174,16 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC | |
} | ||
} | ||
|
||
private static BulkFormat parseBulkFormatHeader(Map<String, List<String>> headers) { | ||
List<String> header = headers.get(BULK_FORMAT_HEADER); | ||
if (header == null || header.isEmpty()) { | ||
return BulkFormat.MARKER_SUFFIX; // default bulk format | ||
} else if (header.size() > 1) { | ||
throw new IllegalArgumentException("Incorrect header [" + BULK_FORMAT_HEADER + "]. Only one value should be provided"); | ||
} | ||
return BulkFormat.parse(header.get(0)); | ||
} | ||
|
||
private static Exception parseFailureException(Exception e) { | ||
if (e instanceof IllegalArgumentException) { | ||
return e; | ||
|
@@ -188,6 +223,7 @@ static class ChunkHandler implements BaseRestHandler.RequestBodyChunkConsumer { | |
request.paramAsBoolean("list_executed_pipelines", false), | ||
allowExplicitIndex, | ||
request.getXContentType(), | ||
parseBulkFormatHeader(request.getHeaders()), | ||
(indexRequest, type) -> items.add(indexRequest), | ||
items::add, | ||
items::add | ||
|
Uh oh!
There was an error while loading. Please reload this page.