From e2d76aaa20e0ccab4452b263a5718b23e46d9c75 Mon Sep 17 00:00:00 2001 From: szroland Date: Mon, 29 Jun 2015 21:55:52 +0200 Subject: [PATCH 01/19] remove _create from POST to match PUT path --- .../create/RestCreateSnapshotAction.java | 2 +- .../rest-api-spec/api/snapshot.create.json | 2 +- .../test/snapshot.create/10_basic.yaml | 36 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.create/10_basic.yaml diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/snapshots/create/RestCreateSnapshotAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/snapshots/create/RestCreateSnapshotAction.java index c62be2b3db6..4bdef344d3f 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/snapshots/create/RestCreateSnapshotAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/snapshots/create/RestCreateSnapshotAction.java @@ -40,7 +40,7 @@ public class RestCreateSnapshotAction extends BaseRestHandler { public RestCreateSnapshotAction(Settings settings, RestController controller, Client client) { super(settings, controller, client); controller.registerHandler(PUT, "/_snapshot/{repository}/{snapshot}", this); - controller.registerHandler(POST, "/_snapshot/{repository}/{snapshot}/_create", this); + controller.registerHandler(POST, "/_snapshot/{repository}/{snapshot}", this); } @Override diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/snapshot.create.json b/rest-api-spec/src/main/resources/rest-api-spec/api/snapshot.create.json index ee00c77918f..29ae2206c85 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/snapshot.create.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/snapshot.create.json @@ -4,7 +4,7 @@ "methods": ["PUT", "POST"], "url": { "path": "/_snapshot/{repository}/{snapshot}", - "paths": ["/_snapshot/{repository}/{snapshot}", "/_snapshot/{repository}/{snapshot}/_create"], + "paths": ["/_snapshot/{repository}/{snapshot}"], "parts": { "repository": { "type": "string", diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.create/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.create/10_basic.yaml new file mode 100644 index 00000000000..b341564e9b5 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.create/10_basic.yaml @@ -0,0 +1,36 @@ +--- +setup: + + - do: + snapshot.create_repository: + repository: test_repo1 + body: + type: fs + settings: + location: "test_repo1" + + - do: + indices.create: + index: test_index + body: + settings: + number_of_shards: 1 + number_of_replicas: 1 + + - do: + cluster.health: + wait_for_status: yellow + +--- +"Create a snapshot": + + - do: + snapshot.create: + repository: test_repo1 + snapshot: test_snapshot + wait_for_completion: true + + - match: { snapshot.snapshot: test_snapshot } + - match: { snapshot.state : SUCCESS } + - match: { snapshot.shards.successful: 1 } + - match: { snapshot.shards.failed : 0 } From 07090b8ee86b7259c684d5523594899ec928ea09 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 30 Jun 2015 00:32:09 +0200 Subject: [PATCH 02/19] percolator: The query parse context should be fetched from the IndexQueryParseService instead of maintaining a thread local cache in the PercolatorQueriesRegistry. Before PercolatorQueriesRegistry had its own cache, because all the queries had to forcefully opt out of caching. Nowadays in master small segments are never cached by the query cache, so the reason for the dedicated cache is no longer valid. --- .../index/percolator/PercolatorQueriesRegistry.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java b/core/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java index 43193b47aea..b7488bf9fe6 100644 --- a/core/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java +++ b/core/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java @@ -23,7 +23,6 @@ import org.apache.lucene.index.Term; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; import org.apache.lucene.util.BytesRef; -import org.apache.lucene.util.CloseableThreadLocal; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; @@ -85,13 +84,6 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent imple private boolean mapUnmappedFieldsAsString; - private CloseableThreadLocal cache = new CloseableThreadLocal() { - @Override - protected QueryParseContext initialValue() { - return new QueryParseContext(shardId.index(), queryParserService); - } - }; - public PercolatorQueriesRegistry(ShardId shardId, @IndexSettings Settings indexSettings, IndexQueryParserService queryParserService, ShardIndexingService indexingService, IndicesLifecycle indicesLifecycle, MapperService mapperService, IndexFieldDataService indexFieldDataService, ShardPercolateService shardPercolateService) { @@ -197,7 +189,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent imple if (type != null) { QueryParseContext.setTypesWithPrevious(new String[]{type}); } - QueryParseContext context = cache.get(); + QueryParseContext context = queryParserService.getParseContext(); try { context.reset(parser); // This means that fields in the query need to exist in the mapping prior to registering this query From fa40680736b18d6fdf7cbe9d9eda32ad13fe748c Mon Sep 17 00:00:00 2001 From: Clinton Gormley Date: Mon, 29 Jun 2015 21:19:36 +0200 Subject: [PATCH 03/19] Build: If SHA files have changed, explain how to update them in the license check exception --- .../license-check/check_license_and_sha.pl | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dev-tools/src/main/resources/license-check/check_license_and_sha.pl b/dev-tools/src/main/resources/license-check/check_license_and_sha.pl index 337ed0c742b..40e78d1debd 100755 --- a/dev-tools/src/main/resources/license-check/check_license_and_sha.pl +++ b/dev-tools/src/main/resources/license-check/check_license_and_sha.pl @@ -28,18 +28,22 @@ sub check_shas_and_licenses { my %licenses = get_files_with('LICENSE'); my %notices = get_files_with('NOTICE'); - my $error = 0; + my $error = 0; + my $sha_error = 0; + for my $jar ( sort keys %new ) { my $old_sha = delete $old{$jar}; unless ($old_sha) { say STDERR "$jar: SHA is missing"; $error++; + $sha_error++; next; } unless ( $old_sha eq $new{$jar} ) { say STDERR "$jar: SHA has changed"; $error++; + $sha_error++; next; } @@ -67,6 +71,7 @@ sub check_shas_and_licenses { unless ($license_found) { say STDERR "$jar: LICENSE is missing"; $error++; + $sha_error++; } unless ($notice_found) { say STDERR "$jar: NOTICE is missing"; @@ -91,6 +96,16 @@ sub check_shas_and_licenses { sort @unused_notices; } + if ($sha_error) { + say STDERR <<"SHAS" + +You can update the SHA files by running: + + $0 --update core + +SHAS + } + exit $error; } From 62cbeecadfe38e2436f171cd2bc4a010d0ed42da Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Tue, 30 Jun 2015 10:30:33 +0100 Subject: [PATCH 04/19] [DOCS] marked pipeline aggregator documentation as Experimental --- .../aggregations/pipeline/avg-bucket-aggregation.asciidoc | 4 ++++ .../aggregations/pipeline/bucket-script-aggregation.asciidoc | 4 ++++ .../aggregations/pipeline/cumulative-sum-aggregation.asciidoc | 4 ++++ .../aggregations/pipeline/derivative-aggregation.asciidoc | 4 ++++ .../aggregations/pipeline/max-bucket-aggregation.asciidoc | 4 ++++ .../aggregations/pipeline/min-bucket-aggregation.asciidoc | 4 ++++ .../aggregations/pipeline/movavg-aggregation.asciidoc | 4 ++++ .../aggregations/pipeline/sum-bucket-aggregation.asciidoc | 4 ++++ 8 files changed, 32 insertions(+) diff --git a/docs/reference/aggregations/pipeline/avg-bucket-aggregation.asciidoc b/docs/reference/aggregations/pipeline/avg-bucket-aggregation.asciidoc index aaedece66d7..8cfeb00dbcd 100644 --- a/docs/reference/aggregations/pipeline/avg-bucket-aggregation.asciidoc +++ b/docs/reference/aggregations/pipeline/avg-bucket-aggregation.asciidoc @@ -1,6 +1,10 @@ [[search-aggregations-pipeline-avg-bucket-aggregation]] === Avg Bucket Aggregation +coming[2.0.0] + +experimental[] + A sibling pipeline aggregation which calculates the (mean) average value of a specified metric in a sibling aggregation. The specified metric must be numeric and the sibling aggregation must be a multi-bucket aggregation. diff --git a/docs/reference/aggregations/pipeline/bucket-script-aggregation.asciidoc b/docs/reference/aggregations/pipeline/bucket-script-aggregation.asciidoc index 2bfac72256a..6e5cb6d0c2a 100644 --- a/docs/reference/aggregations/pipeline/bucket-script-aggregation.asciidoc +++ b/docs/reference/aggregations/pipeline/bucket-script-aggregation.asciidoc @@ -1,6 +1,10 @@ [[search-aggregations-pipeline-bucket-script-aggregation]] === Bucket Script Aggregation +coming[2.0.0] + +experimental[] + A parent pipeline aggregation which executes a script which can perform per bucket computations on specified metrics in the parent multi-bucket aggregation. The specified metric must be numeric and the script must return a numeric value. diff --git a/docs/reference/aggregations/pipeline/cumulative-sum-aggregation.asciidoc b/docs/reference/aggregations/pipeline/cumulative-sum-aggregation.asciidoc index 418ae88ff4f..e1336a1ea32 100644 --- a/docs/reference/aggregations/pipeline/cumulative-sum-aggregation.asciidoc +++ b/docs/reference/aggregations/pipeline/cumulative-sum-aggregation.asciidoc @@ -1,6 +1,10 @@ [[search-aggregations-pipeline-cumulative-sum-aggregation]] === Cumulative Sum Aggregation +coming[2.0.0] + +experimental[] + A parent pipeline aggregation which calculates the cumulative sum of a specified metric in a parent histogram (or date_histogram) aggregation. The specified metric must be numeric and the enclosing histogram must have `min_doc_count` set to `0` (default for `histogram` aggregations). diff --git a/docs/reference/aggregations/pipeline/derivative-aggregation.asciidoc b/docs/reference/aggregations/pipeline/derivative-aggregation.asciidoc index 97804fc067f..234f39c3c92 100644 --- a/docs/reference/aggregations/pipeline/derivative-aggregation.asciidoc +++ b/docs/reference/aggregations/pipeline/derivative-aggregation.asciidoc @@ -1,6 +1,10 @@ [[search-aggregations-pipeline-derivative-aggregation]] === Derivative Aggregation +coming[2.0.0] + +experimental[] + A parent pipeline aggregation which calculates the derivative of a specified metric in a parent histogram (or date_histogram) aggregation. The specified metric must be numeric and the enclosing histogram must have `min_doc_count` set to `0` (default for `histogram` aggregations). diff --git a/docs/reference/aggregations/pipeline/max-bucket-aggregation.asciidoc b/docs/reference/aggregations/pipeline/max-bucket-aggregation.asciidoc index 226ec61065c..b75bedbaf0e 100644 --- a/docs/reference/aggregations/pipeline/max-bucket-aggregation.asciidoc +++ b/docs/reference/aggregations/pipeline/max-bucket-aggregation.asciidoc @@ -1,6 +1,10 @@ [[search-aggregations-pipeline-max-bucket-aggregation]] === Max Bucket Aggregation +coming[2.0.0] + +experimental[] + A sibling pipeline aggregation which identifies the bucket(s) with the maximum value of a specified metric in a sibling aggregation and outputs both the value and the key(s) of the bucket(s). The specified metric must be numeric and the sibling aggregation must be a multi-bucket aggregation. diff --git a/docs/reference/aggregations/pipeline/min-bucket-aggregation.asciidoc b/docs/reference/aggregations/pipeline/min-bucket-aggregation.asciidoc index 478441a27f9..171c59c1fe0 100644 --- a/docs/reference/aggregations/pipeline/min-bucket-aggregation.asciidoc +++ b/docs/reference/aggregations/pipeline/min-bucket-aggregation.asciidoc @@ -1,6 +1,10 @@ [[search-aggregations-pipeline-min-bucket-aggregation]] === Min Bucket Aggregation +coming[2.0.0] + +experimental[] + A sibling pipeline aggregation which identifies the bucket(s) with the minimum value of a specified metric in a sibling aggregation and outputs both the value and the key(s) of the bucket(s). The specified metric must be numeric and the sibling aggregation must be a multi-bucket aggregation. diff --git a/docs/reference/aggregations/pipeline/movavg-aggregation.asciidoc b/docs/reference/aggregations/pipeline/movavg-aggregation.asciidoc index 20677b404af..d612eacfa9e 100644 --- a/docs/reference/aggregations/pipeline/movavg-aggregation.asciidoc +++ b/docs/reference/aggregations/pipeline/movavg-aggregation.asciidoc @@ -1,6 +1,10 @@ [[search-aggregations-pipeline-movavg-aggregation]] === Moving Average Aggregation +coming[2.0.0] + +experimental[] + Given an ordered series of data, the Moving Average aggregation will slide a window across the data and emit the average value of that window. For example, given the data `[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]`, we can calculate a simple moving average with windows size of `5` as follows: diff --git a/docs/reference/aggregations/pipeline/sum-bucket-aggregation.asciidoc b/docs/reference/aggregations/pipeline/sum-bucket-aggregation.asciidoc index b0624fac466..e0909cfcf31 100644 --- a/docs/reference/aggregations/pipeline/sum-bucket-aggregation.asciidoc +++ b/docs/reference/aggregations/pipeline/sum-bucket-aggregation.asciidoc @@ -1,6 +1,10 @@ [[search-aggregations-pipeline-sum-bucket-aggregation]] === Sum Bucket Aggregation +coming[2.0.0] + +experimental[] + A sibling pipeline aggregation which calculates the sum across all bucket of a specified metric in a sibling aggregation. The specified metric must be numeric and the sibling aggregation must be a multi-bucket aggregation. From 4102e263df968301f76ffacfa67db53f0b342a3a Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Tue, 30 Jun 2015 13:25:27 +0200 Subject: [PATCH 05/19] AwaitFix testTracerLog --- .../elasticsearch/transport/AbstractSimpleTransportTests.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/test/java/org/elasticsearch/transport/AbstractSimpleTransportTests.java b/core/src/test/java/org/elasticsearch/transport/AbstractSimpleTransportTests.java index cf70f6ad2f3..11123658665 100644 --- a/core/src/test/java/org/elasticsearch/transport/AbstractSimpleTransportTests.java +++ b/core/src/test/java/org/elasticsearch/transport/AbstractSimpleTransportTests.java @@ -575,6 +575,7 @@ public abstract class AbstractSimpleTransportTests extends ElasticsearchTestCase @Test @TestLogging(value = "test. transport.tracer:TRACE") + @AwaitsFix(bugUrl = "@spinscale is looking into failures: http://build-us-00.elastic.co/job/es_core_master_strong/3986/") public void testTracerLog() throws InterruptedException { TransportRequestHandler handler = new TransportRequestHandler() { @Override From d1a29a63d2ea1552ce20bf2613330ff3fd5b740b Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 30 Jun 2015 11:15:55 +0200 Subject: [PATCH 06/19] Decode URL.getPath before resolving a real file URL with spaces are URL-Encoded and need to be decoded before they can be used to open files etc. --- core/src/main/java/org/elasticsearch/bootstrap/JarHell.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/bootstrap/JarHell.java b/core/src/main/java/org/elasticsearch/bootstrap/JarHell.java index 90fb38c68ee..2884da4fe1c 100644 --- a/core/src/main/java/org/elasticsearch/bootstrap/JarHell.java +++ b/core/src/main/java/org/elasticsearch/bootstrap/JarHell.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.io.PathUtils; import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; +import java.net.URLDecoder; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; @@ -55,12 +56,12 @@ class JarHell { final Map clazzes = new HashMap<>(32768); Set seenJars = new HashSet<>(); for (final URL url : ((URLClassLoader)loader).getURLs()) { - String path = url.getPath(); + String path = URLDecoder.decode(url.getPath(), "UTF-8"); if (path.endsWith(".jar")) { if (!seenJars.add(path)) { continue; // we can't fail because of sheistiness with joda-time } - try (JarFile file = new JarFile(url.getPath())) { + try (JarFile file = new JarFile(path)) { Manifest manifest = file.getManifest(); if (manifest != null) { // inspect Manifest: give a nice error if jar requires a newer java version From 84acb65ca18c9d53faea1d02a69f400bf094b871 Mon Sep 17 00:00:00 2001 From: Clinton Gormley Date: Tue, 30 Jun 2015 13:53:04 +0200 Subject: [PATCH 07/19] Docs: Documented delayed allocation settings Relates to: #11712 --- docs/reference/cluster/health.asciidoc | 30 +++-- .../index-modules/allocation.asciidoc | 127 +----------------- .../index-modules/allocation/delayed.asciidoc | 91 +++++++++++++ .../allocation/filtering.asciidoc | 97 +++++++++++++ .../allocation/total_shards.asciidoc | 26 ++++ 5 files changed, 238 insertions(+), 133 deletions(-) create mode 100644 docs/reference/index-modules/allocation/delayed.asciidoc create mode 100644 docs/reference/index-modules/allocation/filtering.asciidoc create mode 100644 docs/reference/index-modules/allocation/total_shards.asciidoc diff --git a/docs/reference/cluster/health.asciidoc b/docs/reference/cluster/health.asciidoc index a58a0924fce..7d9bdc1b041 100644 --- a/docs/reference/cluster/health.asciidoc +++ b/docs/reference/cluster/health.asciidoc @@ -7,18 +7,22 @@ of the cluster. [source,js] -------------------------------------------------- $ curl -XGET 'http://localhost:9200/_cluster/health?pretty=true' -{ - "cluster_name" : "testcluster", - "status" : "green", - "timed_out" : false, - "number_of_nodes" : 2, - "number_of_data_nodes" : 2, - "active_primary_shards" : 5, - "active_shards" : 10, - "relocating_shards" : 0, - "initializing_shards" : 0, +{ + "cluster_name" : "testcluster", + "status" : "green", + "timed_out" : false, + "number_of_nodes" : 2, + "number_of_data_nodes" : 2, + "active_primary_shards" : 5, + "active_shards" : 10, + "relocating_shards" : 0, + "initializing_shards" : 0, "unassigned_shards" : 0, - "number_of_pending_tasks" : 0 + "delayed_unassigned_shards": 0, + "number_of_pending_tasks" : 0, + "number_of_in_flight_fetch": 0, + "task_max_waiting_in_queue_millis": 0, + "active_shards_percent_as_number": 100 } -------------------------------------------------- @@ -61,14 +65,14 @@ The cluster health API accepts the following request parameters: `wait_for_status`:: One of `green`, `yellow` or `red`. Will wait (until the timeout provided) until the status of the cluster changes to the one - provided or better, i.e. `green` > `yellow` > `red`. By default, will not + provided or better, i.e. `green` > `yellow` > `red`. By default, will not wait for any status. `wait_for_relocating_shards`:: A number controlling to how many relocating shards to wait for. Usually will be `0` to indicate to wait till all relocations have happened. Defaults to not wait. - + `wait_for_active_shards`:: A number controlling to how many active shards to wait for. Defaults to not wait. diff --git a/docs/reference/index-modules/allocation.asciidoc b/docs/reference/index-modules/allocation.asciidoc index 4cc07060b62..c0a94c85eb5 100644 --- a/docs/reference/index-modules/allocation.asciidoc +++ b/docs/reference/index-modules/allocation.asciidoc @@ -2,130 +2,17 @@ == Index Shard Allocation This module provides per-index settings to control the allocation of shards to -nodes. +nodes: -[float] -[[shard-allocation-filtering]] -=== Shard Allocation Filtering +* <>: Controlling which shards are allocated to which nodes. +* <>: Delaying allocation of unassigned shards caused by a node leaving. +* <>: A hard limit on the number of shards from the same index per node. -Shard allocation filtering allows you to specify which nodes are allowed -to host the shards of a particular index. +include::allocation/filtering.asciidoc[] -NOTE: The per-index shard allocation filters explained below work in -conjunction with the cluster-wide allocation filters explained in -<>. +include::allocation/delayed.asciidoc[] -It is possible to assign arbitrary metadata attributes to each node at -startup. For instance, nodes could be assigned a `rack` and a `group` -attribute as follows: - -[source,sh] ------------------------- -bin/elasticsearch --node.rack rack1 --node.size big <1> ------------------------- -<1> These attribute settings can also be specfied in the `elasticsearch.yml` config file. - -These metadata attributes can be used with the -`index.routing.allocation.*` settings to allocate an index to a particular -group of nodes. For instance, we can move the index `test` to either `big` or -`medium` nodes as follows: - -[source,json] ------------------------- -PUT test/_settings -{ - "index.routing.allocation.include.size": "big,medium" -} ------------------------- -// AUTOSENSE - -Alternatively, we can move the index `test` away from the `small` nodes with -an `exclude` rule: - -[source,json] ------------------------- -PUT test/_settings -{ - "index.routing.allocation.exclude.size": "small" -} ------------------------- -// AUTOSENSE - -Multiple rules can be specified, in which case all conditions must be -satisfied. For instance, we could move the index `test` to `big` nodes in -`rack1` with the following: - -[source,json] ------------------------- -PUT test/_settings -{ - "index.routing.allocation.include.size": "big", - "index.routing.allocation.include.rack": "rack1" -} ------------------------- -// AUTOSENSE - -NOTE: If some conditions cannot be satisfied then shards will not be moved. - -The following settings are _dynamic_, allowing live indices to be moved from -one set of nodes to another: - -`index.routing.allocation.include.{attribute}`:: - - Assign the index to a node whose `{attribute}` has at least one of the - comma-separated values. - -`index.routing.allocation.require.{attribute}`:: - - Assign the index to a node whose `{attribute}` has _all_ of the - comma-separated values. - -`index.routing.allocation.exclude.{attribute}`:: - - Assign the index to a node whose `{attribute}` has _none_ of the - comma-separated values. - -These special attributes are also supported: - -[horizontal] -`_name`:: Match nodes by node name -`_ip`:: Match nodes by IP address (the IP address associated with the hostname) -`_host`:: Match nodes by hostname - -All attribute values can be specified with wildcards, eg: - -[source,json] ------------------------- -PUT test/_settings -{ - "index.routing.allocation.include._ip": "192.168.2.*" -} ------------------------- -// AUTOSENSE - -[float] -=== Total Shards Per Node - -The cluster-level shard allocator tries to spread the shards of a single index -across as many nodes as possible. However, depending on how many shards and -indices you have, and how big they are, it may not always be possible to spread -shards evenly. - -The following _dynamic_ setting allows you to specify a hard limit on the total -number of shards from a single index allowed per node: - -`index.routing.allocation.total_shards_per_node`:: - - The maximum number of shards (replicas and primaries) that will be - allocated to a single node. Defaults to unbounded. - -[WARNING] -======================================= -This setting imposes a hard limit which can result in some shards not -being allocated. - -Use with caution. -======================================= +include::allocation/total_shards.asciidoc[] diff --git a/docs/reference/index-modules/allocation/delayed.asciidoc b/docs/reference/index-modules/allocation/delayed.asciidoc new file mode 100644 index 00000000000..31f5b8092f3 --- /dev/null +++ b/docs/reference/index-modules/allocation/delayed.asciidoc @@ -0,0 +1,91 @@ +[[delayed-allocation]] +=== Delaying allocation when a node leaves + +When a node leaves the cluster for whatever reason, intentional or otherwise, +the master reacts by: + +* Promoting a replica shard to primary to replace any primaries that were on the node. +* Allocating replica shards to replace the missing replicas (assuming there are enough nodes). +* Rebalancing shards evenly across the remaining nodes. + +These actions are intended to protect the cluster against data loss by +ensuring that every shard is fully replicated as soon as possible. + +Even though we throttle concurrent recoveries both at the +<> and at the <>, this +``shard-shuffle'' can still put a lot of extra load on the cluster which +may not be necessary if the missing node is likely to return soon. Imagine +this scenario: + +* Node 5 loses network connectivity. +* The master promotes a replica shard to primary for each primary that was on Node 5. +* The master allocates new replicas to other nodes in the cluster. +* Each new replica makes an entire copy of the primary shard across the network. +* More shards are moved to different nodes to rebalance the cluster. +* Node 5 returns after a few minutes. +* The master rebalances the cluster by allocating shards to Node 5. + +If the master had just waited for a few minutes, then the missing shards could +have been re-allocated to Node 5 with the minimum of network traffic. This +process would be even quicker for idle shards (shards not receiving indexing +requests) which have been automatically <>. + +The allocation of replica shards which become unassigned because a node has +left can be delayed with the `index.unassigned.node_left.delayed_timeout` +dynamic setting, which defaults to `0` (reassign shards immediately). + +This setting can be updated on a live index (or on all indices): + +[source,js] +------------------------------ +PUT /_all/_settings +{ + "settings": { + "index.unassigned.node_left.delayed_timeout": "5m" + } +} +------------------------------ +// AUTOSENSE + +With delayed allocation enabled, the above scenario changes to look like this: + +* Node 5 loses network connectivity. +* The master promotes a replica shard to primary for each primary that was on Node 5. +* The master logs a message that allocation of unassigned shards has been delayed, and for how long. +* The cluster remains yellow because there are unassigned replica shards. +* Node 5 returns after a few minutes, before the `timeout` expires. +* The missing replicas are re-allocated to Node 5 (and sync-flushed shards recover almost immediately). + +NOTE: This setting will not affect the promotion of replicas to primaries, nor +will it affect the assignment of replicas that have not been assigned +previously. + +==== Monitoring delayed unassigned shards + +The number of shards whose allocation has been delayed by this timeout setting +can be viewed with the <>: + +[source,js] +------------------------------ +GET _cluster/health <1> +------------------------------ +<1> This request will return a `delayed_unassigned_shards` value. + +==== Removing a node permanently + +If a node is not going to return and you would like Elasticsearch to allocate +the missing shards immediately, just update the timeout to zero: + + +[source,js] +------------------------------ +PUT /_all/_settings +{ + "settings": { + "index.unassigned.node_left.delayed_timeout": "0" + } +} +------------------------------ +// AUTOSENSE + +You can reset the timeout as soon as the missing shards have started to recover. diff --git a/docs/reference/index-modules/allocation/filtering.asciidoc b/docs/reference/index-modules/allocation/filtering.asciidoc new file mode 100644 index 00000000000..d5e30fb76bb --- /dev/null +++ b/docs/reference/index-modules/allocation/filtering.asciidoc @@ -0,0 +1,97 @@ +[[shard-allocation-filtering]] +=== Shard Allocation Filtering + +Shard allocation filtering allows you to specify which nodes are allowed +to host the shards of a particular index. + +NOTE: The per-index shard allocation filters explained below work in +conjunction with the cluster-wide allocation filters explained in +<>. + +It is possible to assign arbitrary metadata attributes to each node at +startup. For instance, nodes could be assigned a `rack` and a `group` +attribute as follows: + +[source,sh] +------------------------ +bin/elasticsearch --node.rack rack1 --node.size big <1> +------------------------ +<1> These attribute settings can also be specfied in the `elasticsearch.yml` config file. + +These metadata attributes can be used with the +`index.routing.allocation.*` settings to allocate an index to a particular +group of nodes. For instance, we can move the index `test` to either `big` or +`medium` nodes as follows: + +[source,json] +------------------------ +PUT test/_settings +{ + "index.routing.allocation.include.size": "big,medium" +} +------------------------ +// AUTOSENSE + +Alternatively, we can move the index `test` away from the `small` nodes with +an `exclude` rule: + +[source,json] +------------------------ +PUT test/_settings +{ + "index.routing.allocation.exclude.size": "small" +} +------------------------ +// AUTOSENSE + +Multiple rules can be specified, in which case all conditions must be +satisfied. For instance, we could move the index `test` to `big` nodes in +`rack1` with the following: + +[source,json] +------------------------ +PUT test/_settings +{ + "index.routing.allocation.include.size": "big", + "index.routing.allocation.include.rack": "rack1" +} +------------------------ +// AUTOSENSE + +NOTE: If some conditions cannot be satisfied then shards will not be moved. + +The following settings are _dynamic_, allowing live indices to be moved from +one set of nodes to another: + +`index.routing.allocation.include.{attribute}`:: + + Assign the index to a node whose `{attribute}` has at least one of the + comma-separated values. + +`index.routing.allocation.require.{attribute}`:: + + Assign the index to a node whose `{attribute}` has _all_ of the + comma-separated values. + +`index.routing.allocation.exclude.{attribute}`:: + + Assign the index to a node whose `{attribute}` has _none_ of the + comma-separated values. + +These special attributes are also supported: + +[horizontal] +`_name`:: Match nodes by node name +`_ip`:: Match nodes by IP address (the IP address associated with the hostname) +`_host`:: Match nodes by hostname + +All attribute values can be specified with wildcards, eg: + +[source,json] +------------------------ +PUT test/_settings +{ + "index.routing.allocation.include._ip": "192.168.2.*" +} +------------------------ +// AUTOSENSE diff --git a/docs/reference/index-modules/allocation/total_shards.asciidoc b/docs/reference/index-modules/allocation/total_shards.asciidoc new file mode 100644 index 00000000000..3e1b3ab16e8 --- /dev/null +++ b/docs/reference/index-modules/allocation/total_shards.asciidoc @@ -0,0 +1,26 @@ +[[allocation-total-shards]] +=== Total Shards Per Node + +The cluster-level shard allocator tries to spread the shards of a single index +across as many nodes as possible. However, depending on how many shards and +indices you have, and how big they are, it may not always be possible to spread +shards evenly. + +The following _dynamic_ setting allows you to specify a hard limit on the total +number of shards from a single index allowed per node: + +`index.routing.allocation.total_shards_per_node`:: + + The maximum number of shards (replicas and primaries) that will be + allocated to a single node. Defaults to unbounded. + +[WARNING] +======================================= +This setting imposes a hard limit which can result in some shards not +being allocated. + +Use with caution. +======================================= + + + From f26672c18421c84afe52b3eef24f0abf064ba499 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Tue, 30 Jun 2015 08:17:18 +0200 Subject: [PATCH 08/19] Release: Build two RPMS, signed and unsigned In order to support older RPM based distributions like CentOS5, we should have one RPM available, which is not signed. This commit creates an unsigned RPM first, then moves it over to target/releases during the build, then builds a signed RPM. The unsigned one is uploaded via S3, where as the signed one is used for the repositories. In addition, you can now build an RPM without having to specify any gpg credentials due to offloading this into a maven profile that is only activated when specifying `rpm.sign` property. Closes #11587 --- core/pom.xml | 31 +++++++++++++++++++++++++------ dev-tools/build_release.py | 33 +++++++++++++++++++-------------- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 502bd63da9c..7a5f1a631f0 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -819,7 +819,7 @@ org.codehaus.mojo rpm-maven-plugin - 2.1.2 + 2.1.3 Elasticsearch Application/Internet @@ -834,11 +834,6 @@ 755 root root - ${gpg.key} - ${gpg.keyring} - - ${gpg.passphrase} - @@ -1101,5 +1096,29 @@ + + sign-rpm + + + rpm.sign + true + + + + + + org.codehaus.mojo + rpm-maven-plugin + + ${gpg.key} + ${gpg.keyring} + + ${gpg.passphrase} + + + + + + diff --git a/dev-tools/build_release.py b/dev-tools/build_release.py index 8ae300d98fd..32f7b703aa2 100644 --- a/dev-tools/build_release.py +++ b/dev-tools/build_release.py @@ -239,7 +239,7 @@ def run_mvn(*cmd): for c in cmd: run('%s; %s %s' % (java_exe(), MVN, c)) -def build_release(run_tests=False, dry_run=True, cpus=1, bwc_version=None): +def build_release(release_version, run_tests=False, dry_run=True, cpus=1, bwc_version=None): target = 'deploy' if dry_run: target = 'package' @@ -251,12 +251,25 @@ def build_release(run_tests=False, dry_run=True, cpus=1, bwc_version=None): print('Running Backwards compatibility tests against version [%s]' % (bwc_version)) run_mvn('clean', 'test -Dtests.filter=@backwards -Dtests.bwc.version=%s -Dtests.bwc=true -Dtests.jvms=1' % bwc_version) run_mvn('clean test-compile -Dforbidden.test.signatures="org.apache.lucene.util.LuceneTestCase\$AwaitsFix @ Please fix all bugs before release"') - gpg_args = '-Dgpg.key="%s" -Dgpg.passphrase="%s" -Ddeb.sign=true' % (env.get('GPG_KEY_ID'), env.get('GPG_PASSPHRASE')) + gpg_args = '-Dgpg.key="%s" -Dgpg.passphrase="%s" -Ddeb.sign=true -Drpm.sign=true' % (env.get('GPG_KEY_ID'), env.get('GPG_PASSPHRASE')) if env.get('GPG_KEYRING'): gpg_args += ' -Dgpg.keyring="%s"' % env.get('GPG_KEYRING') run_mvn('clean %s -DskipTests %s' % (target, gpg_args)) success = False try: + # create unsigned RPM first for downloads.elasticsearch.org + run_mvn('-DskipTests rpm:rpm') + # move unsigned RPM to target/releases + # this is an oddness of RPM that is attaches -1 so we have to rename it + rpm = os.path.join('target/rpm/elasticsearch/RPMS/noarch/', 'elasticsearch-%s-1.noarch.rpm' % release_version) + if os.path.isfile(rpm): + log('RPM [%s] contains: ' % rpm) + run('rpm -pqli %s' % rpm) + renamed_rpm = os.path.join('target/releases/', 'elasticsearch-%s.noarch.rpm' % release_version) + shutil.move(rpm, renamed_rpm) + else: + raise RuntimeError('Could not find required RPM at %s' % rpm) + # now create signed RPM for repositories run_mvn('-DskipTests rpm:rpm %s' % (gpg_args)) success = True finally: @@ -346,23 +359,15 @@ def find_release_version(src_branch): raise RuntimeError('Could not find release version in branch %s' % src_branch) def artifact_names(release, path = ''): - return [os.path.join(path, 'elasticsearch-%s.%s' % (release, t)) for t in ['deb', 'tar.gz', 'zip']] + artifacts = [os.path.join(path, 'elasticsearch-%s.%s' % (release, t)) for t in ['deb', 'tar.gz', 'zip']] + artifacts.append(os.path.join(path, 'elasticsearch-%s.noarch.rpm' % (release))) + return artifacts def get_artifacts(release): common_artifacts = artifact_names(release, 'target/releases/') for f in common_artifacts: if not os.path.isfile(f): raise RuntimeError('Could not find required artifact at %s' % f) - rpm = os.path.join('target/rpm/elasticsearch/RPMS/noarch/', 'elasticsearch-%s-1.noarch.rpm' % release) - if os.path.isfile(rpm): - log('RPM [%s] contains: ' % rpm) - run('rpm -pqli %s' % rpm) - # this is an oddness of RPM that is attches -1 so we have to rename it - renamed_rpm = os.path.join('target/rpm/elasticsearch/RPMS/noarch/', 'elasticsearch-%s.noarch.rpm' % release) - shutil.move(rpm, renamed_rpm) - common_artifacts.append(renamed_rpm) - else: - raise RuntimeError('Could not find required artifact at %s' % rpm) return common_artifacts # Checks the jar files in each package @@ -754,7 +759,7 @@ if __name__ == '__main__': print(' Running maven builds now and publish to Sonatype - run-tests [%s]' % run_tests) else: print(' Running maven builds now run-tests [%s]' % run_tests) - build_release(run_tests=run_tests, dry_run=dry_run, cpus=cpus, bwc_version=find_bwc_version(release_version, bwc_path)) + build_release(release_version, run_tests=run_tests, dry_run=dry_run, cpus=cpus, bwc_version=find_bwc_version(release_version, bwc_path)) artifacts = get_artifacts(release_version) print('Checking if all artifacts contain the same jars') check_artifacts_for_same_jars(artifacts) From e7eb9cf4de13620c473512dcbf0259d390ed471d Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 29 Jun 2015 12:53:08 +0200 Subject: [PATCH 09/19] Ban java serialization We had several problems with Java Serializatin in the past. At some point in the Java 1.7.x series JDKs where not compatible anymore when java serialization (ObjectStream) was used to exchange objects. In elasticsearch we used this to serialize exceptions across the wire which caused several problems with incompatible JDKs. While causing lot of trouble this essentially prevented users from moving forward and upgrade their JVMs. To prevent these kind of issues this commit removes the dependency on java serialization entirely and bans the usage of ObjectOutputStream and ObjectInputStream entirely. Yet, we can't fully serialize all exception anymore such that this commit is best effort and adds hand written serialization to all elasticsearch exceptions as well to a selected set of JDK and Lucene exceptions. (see StreamOutput#writeThrowable / StreamInput.readThrowable). Stacktraces should be preserved for all exceptions while several names might be replaced with ElasticsearchException if there is no mapping for the given exception. --- .../elasticsearch/ElasticsearchException.java | 273 +++++++++++++++++- .../ElasticsearchGenerationException.java | 8 + .../ElasticsearchNullPointerException.java | 38 --- .../ElasticsearchParseException.java | 6 + .../ElasticsearchTimeoutException.java | 7 + .../action/FailedNodeException.java | 15 + .../NoShardAvailableActionException.java | 7 + .../action/NoSuchNodeException.java | 9 + .../action/PrimaryMissingActionException.java | 7 + .../action/RoutingMissingException.java | 19 ++ .../action/TimestampParsingException.java | 15 + .../action/UnavailableShardsException.java | 7 + .../search/ReduceSearchPhaseException.java | 12 +- .../search/SearchPhaseExecutionException.java | 26 +- .../support/HandledTransportAction.java | 4 +- ...roadcastShardOperationFailedException.java | 7 + ...licationShardOperationFailedException.java | 44 --- .../TransportReplicationAction.java | 14 +- .../transport/NoNodeAvailableException.java | 7 + ...ompatibleClusterStateVersionException.java | 7 + .../cluster/block/ClusterBlockException.java | 28 ++ .../ProcessClusterEventTimeoutException.java | 7 + .../cluster/node/DiscoveryNode.java | 17 +- .../IllegalShardRoutingStateException.java | 16 + .../cluster/routing/RoutingException.java | 7 + .../routing/RoutingValidationException.java | 16 + .../java/org/elasticsearch/common/Base64.java | 111 ------- .../common/blobstore/BlobStoreException.java | 7 + .../breaker/CircuitBreakingException.java | 17 ++ .../common/io/ThrowableObjectInputStream.java | 99 ------- .../io/ThrowableObjectOutputStream.java | 68 ----- .../common/io/stream/StreamInput.java | 60 +++- .../common/io/stream/StreamOutput.java | 42 ++- .../elasticsearch/common/lucene/Lucene.java | 4 + .../settings/NoClassSettingsException.java | 12 +- .../common/settings/SettingsException.java | 7 + .../transport/InetSocketTransportAddress.java | 6 - .../common/transport/TransportAddress.java | 2 +- .../common/util/CancellableThreads.java | 8 +- .../EsRejectedExecutionException.java | 9 +- .../UncategorizedExecutionException.java | 7 + .../MasterNotDiscoveredException.java | 7 + .../env/FailedToResolveConfigException.java | 7 + .../gateway/GatewayException.java | 7 + .../elasticsearch/http/BindHttpException.java | 12 +- .../org/elasticsearch/http/HttpException.java | 7 + .../index/AlreadyExpiredException.java | 25 ++ .../elasticsearch/index/IndexException.java | 14 + .../IndexShardAlreadyExistsException.java | 7 + .../index/IndexShardMissingException.java | 7 + .../index/engine/CloseEngineException.java | 38 --- .../engine/CreateFailedEngineException.java | 17 ++ .../DeleteByQueryFailedEngineException.java | 7 + .../engine/DeleteFailedEngineException.java | 7 + .../DocumentAlreadyExistsException.java | 7 + .../engine/DocumentMissingException.java | 7 + .../DocumentSourceMissingException.java | 7 + .../engine/EngineAlreadyStartedException.java | 32 -- .../index/engine/EngineClosedException.java | 7 + .../EngineCreationFailureException.java | 7 + .../index/engine/EngineException.java | 7 + .../engine/FlushFailedEngineException.java | 7 +- .../FlushNotAllowedEngineException.java | 7 + .../ForceMergeFailedEngineException.java | 7 + .../engine/IndexFailedEngineException.java | 17 ++ .../index/engine/RecoveryEngineException.java | 15 + .../engine/RefreshFailedEngineException.java | 7 + .../engine/RollbackFailedEngineException.java | 32 -- .../RollbackNotAllowedEngineException.java | 32 -- .../engine/SnapshotFailedEngineException.java | 6 + .../VersionConflictEngineException.java | 17 +- .../mapper/MapperCompressionException.java | 34 --- .../index/mapper/MapperException.java | 6 + .../index/mapper/MapperParsingException.java | 7 + .../index/mapper/MergeMappingException.java | 14 + .../mapper/StrictDynamicMappingException.java | 7 + .../index/percolator/PercolatorException.java | 7 + .../index/query/QueryParsingException.java | 26 +- .../IllegalIndexShardStateException.java | 15 + .../shard/IndexShardClosedException.java | 8 + .../shard/IndexShardCreationException.java | 8 + .../index/shard/IndexShardException.java | 17 ++ .../IndexShardNotRecoveringException.java | 8 + .../shard/IndexShardNotStartedException.java | 8 + .../shard/IndexShardRecoveringException.java | 8 + .../shard/IndexShardRecoveryException.java | 7 + .../shard/IndexShardRelocatedException.java | 8 + .../shard/IndexShardStartedException.java | 8 + .../shard/TranslogRecoveryPerformer.java | 13 + .../snapshots/IndexShardRestoreException.java | 7 + .../IndexShardRestoreFailedException.java | 7 + .../IndexShardSnapshotException.java | 7 + .../IndexShardSnapshotFailedException.java | 7 + .../index/store/StoreException.java | 11 +- .../translog/TranslogCorruptedException.java | 7 + .../index/translog/TranslogException.java | 7 + .../translog/TruncatedTranslogException.java | 8 + .../indices/AliasFilterParsingException.java | 6 + .../indices/IndexAlreadyExistsException.java | 7 + .../indices/IndexClosedException.java | 7 + .../indices/IndexCreationException.java | 7 + .../indices/IndexMissingException.java | 7 + ...ndexPrimaryShardNotAllocatedException.java | 6 + .../IndexTemplateAlreadyExistsException.java | 15 + .../IndexTemplateMissingException.java | 14 + .../indices/InvalidAliasNameException.java | 7 + .../indices/InvalidIndexNameException.java | 7 + .../InvalidIndexTemplateException.java | 15 + .../indices/InvalidTypeNameException.java | 7 + .../indices/TypeMissingException.java | 6 + .../recovery/DelayRecoveryException.java | 8 +- .../recovery/IgnoreRecoveryException.java | 38 --- .../RecoverFilesRecoveryException.java | 17 ++ .../recovery/RecoveryFailedException.java | 7 + .../node/NodeClosedException.java | 7 + .../percolator/PercolateException.java | 20 +- .../repositories/RepositoryException.java | 15 + .../RepositoryMissingException.java | 8 + .../RepositoryVerificationException.java | 8 + .../elasticsearch/rest/HasRestHeaders.java | 4 +- .../alias/delete/AliasesMissingException.java | 14 + .../java/org/elasticsearch/script/Script.java | 4 +- .../elasticsearch/script/ScriptException.java | 7 + .../ExpressionScriptCompilationException.java | 6 + .../ExpressionScriptExecutionException.java | 8 + .../GroovyScriptCompilationException.java | 7 + .../GroovyScriptExecutionException.java | 10 +- .../search/SearchContextException.java | 7 + .../search/SearchContextMissingException.java | 15 + .../elasticsearch/search/SearchException.java | 19 ++ .../search/SearchParseException.java | 30 +- .../AggregationExecutionException.java | 7 + .../AggregationInitializationException.java | 7 + .../InvalidAggregationPathException.java | 7 + .../builder/SearchSourceBuilderException.java | 7 + .../dfs/DfsPhaseExecutionException.java | 7 + .../fetch/FetchPhaseExecutionException.java | 11 +- .../query/QueryPhaseExecutionException.java | 7 + .../suggest/SuggestBuilderException.java | 37 --- .../warmer/IndexWarmerMissingException.java | 14 + .../ConcurrentSnapshotExecutionException.java | 7 +- .../InvalidSnapshotNameException.java | 7 + .../snapshots/SnapshotCreationException.java | 7 +- .../snapshots/SnapshotException.java | 19 ++ .../snapshots/SnapshotMissingException.java | 12 +- .../snapshots/SnapshotRestoreException.java | 7 + .../ActionNotFoundTransportException.java | 16 + .../transport/ActionTransportException.java | 31 +- .../transport/BindTransportException.java | 8 +- .../transport/ConnectTransportException.java | 19 ++ .../FailedCommunicationException.java | 34 --- .../transport/NodeDisconnectedException.java | 7 + .../transport/NodeNotConnectedException.java | 9 +- .../NodeShouldNotConnectException.java | 7 + .../NotSerializableTransportException.java | 8 + .../ReceiveTimeoutTransportException.java | 7 + .../transport/RemoteTransportException.java | 9 +- ...ponseHandlerFailureTransportException.java | 10 +- ...onseHandlerNotFoundTransportException.java | 37 --- .../SendRequestTransportException.java | 7 + .../transport/TransportException.java | 6 + .../TransportSerializationException.java | 8 +- .../transport/local/LocalTransport.java | 6 +- .../local/LocalTransportChannel.java | 20 +- .../netty/MessageChannelHandler.java | 4 +- .../netty/NettyTransportChannel.java | 19 +- .../netty/SizeHeaderFrameDecoder.java | 9 +- .../ElasticsearchExceptionTests.java | 56 +++- .../ExceptionRegistrationTests.java | 127 ++++++++ .../client/AbstractClientHeadersTests.java | 2 +- .../cluster/node/DiscoveryNodeTests.java | 74 ----- .../common/util/CancellableThreadsTest.java | 2 +- .../rest/BytesRestResponseTests.java | 6 +- .../snapshots/RepositoriesTests.java | 2 - .../resources/forbidden/all-signatures.txt | 6 + 175 files changed, 1896 insertions(+), 928 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/ElasticsearchNullPointerException.java delete mode 100644 core/src/main/java/org/elasticsearch/action/support/replication/ReplicationShardOperationFailedException.java delete mode 100644 core/src/main/java/org/elasticsearch/common/io/ThrowableObjectInputStream.java delete mode 100644 core/src/main/java/org/elasticsearch/common/io/ThrowableObjectOutputStream.java delete mode 100644 core/src/main/java/org/elasticsearch/index/engine/CloseEngineException.java delete mode 100644 core/src/main/java/org/elasticsearch/index/engine/EngineAlreadyStartedException.java delete mode 100644 core/src/main/java/org/elasticsearch/index/engine/RollbackFailedEngineException.java delete mode 100644 core/src/main/java/org/elasticsearch/index/engine/RollbackNotAllowedEngineException.java delete mode 100644 core/src/main/java/org/elasticsearch/index/mapper/MapperCompressionException.java delete mode 100644 core/src/main/java/org/elasticsearch/indices/recovery/IgnoreRecoveryException.java delete mode 100644 core/src/main/java/org/elasticsearch/search/suggest/SuggestBuilderException.java delete mode 100644 core/src/main/java/org/elasticsearch/transport/FailedCommunicationException.java delete mode 100644 core/src/main/java/org/elasticsearch/transport/ResponseHandlerNotFoundTransportException.java create mode 100644 core/src/test/java/org/elasticsearch/ExceptionRegistrationTests.java delete mode 100644 core/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeTests.java diff --git a/core/src/main/java/org/elasticsearch/ElasticsearchException.java b/core/src/main/java/org/elasticsearch/ElasticsearchException.java index 627c1b674a1..479363b7462 100644 --- a/core/src/main/java/org/elasticsearch/ElasticsearchException.java +++ b/core/src/main/java/org/elasticsearch/ElasticsearchException.java @@ -22,17 +22,18 @@ package org.elasticsearch; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.Tuple; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexException; import org.elasticsearch.rest.HasRestHeaders; import org.elasticsearch.rest.RestStatus; import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.util.*; /** @@ -41,6 +42,7 @@ import java.util.*; public class ElasticsearchException extends RuntimeException implements ToXContent { public static final String REST_EXCEPTION_SKIP_CAUSE = "rest.exception.skip_cause"; + static final Map> MAPPING; /** * Construct a ElasticsearchException with the specified detail message. @@ -62,6 +64,12 @@ public class ElasticsearchException extends RuntimeException implements ToXConte super(msg, cause); } + public ElasticsearchException(StreamInput in) throws IOException { + super(in.readOptionalString(), in.readThrowable()); //TODO readOptionalThrowable + readStackTrace(this, in); + + } + /** * Returns the rest status code associated with this exception. */ @@ -152,19 +160,73 @@ public class ElasticsearchException extends RuntimeException implements ToXConte } } + public void writeTo(StreamOutput out) throws IOException { + out.writeOptionalString(this.getMessage()); + out.writeThrowable(this.getCause()); + writeStackTraces(this, out); + } + + public static ElasticsearchException readException(StreamInput input) throws IOException { + final String name = input.readString(); + Constructor elasticsearchException = MAPPING.get(name); + if (elasticsearchException == null) { + throw new IllegalStateException("unknown exception with name: " + name); + } + try { + return elasticsearchException.newInstance(input); + } catch (InstantiationException|IllegalAccessException|InvocationTargetException e) { + throw new IOException("failed to read exception: [" + name + "]", e); + } + } + + public static void writeException(ElasticsearchException ex, StreamOutput output) throws IOException { + output.writeString(ex.getClass().getName()); + ex.writeTo(output); + } + /** * A base class for exceptions that should carry rest headers */ @SuppressWarnings("unchecked") - public static class WithRestHeaders extends ElasticsearchException implements HasRestHeaders { + public static class WithRestHeadersException extends ElasticsearchException implements HasRestHeaders { private final ImmutableMap> headers; - public WithRestHeaders(String msg, Tuple... headers) { + public WithRestHeadersException(String msg, Tuple... headers) { super(msg); this.headers = headers(headers); } + public WithRestHeadersException(StreamInput in) throws IOException { + super(in); + int numKeys = in.readVInt(); + ImmutableMap.Builder> builder = ImmutableMap.builder(); + for (int i = 0; i < numKeys; i++) { + String key = in.readString(); + int numValues = in.readVInt(); + ArrayList headers = new ArrayList<>(numValues); + for (int j = 0; j < numValues; j++) { + headers.add(in.readString()); + } + builder.put(key, headers); + } + headers = builder.build(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeVInt(headers.size()); + for (Map.Entry> entry : headers.entrySet()) { + out.writeString(entry.getKey()); + out.writeVInt(entry.getValue().size()); + for (String v : entry.getValue()) { + out.writeString(v); + } + + } + } + @Override public ImmutableMap> getHeaders() { return headers; @@ -290,4 +352,205 @@ public class ElasticsearchException extends RuntimeException implements ToXConte public String toString() { return ExceptionsHelper.detailedMessage(this).trim(); } + + public static T readStackTrace(T throwable, StreamInput in) throws IOException { + int stackTraceElements = in.readVInt(); + StackTraceElement[] stackTrace = new StackTraceElement[stackTraceElements]; + for (int i = 0; i < stackTraceElements; i++) { + String declaringClasss = in.readString(); + String fielName = in.readString(); + String methodName = in.readString(); + int lineNumber = in.readVInt(); + stackTrace[i] = new StackTraceElement(declaringClasss,methodName, fielName, lineNumber); + } + throwable.setStackTrace(stackTrace); + + int numSuppressed = in.readVInt(); + for (int i = 0; i < numSuppressed; i++) { + throwable.addSuppressed(in.readThrowable()); + } + return throwable; + } + + public static T writeStackTraces(T throwable, StreamOutput out) throws IOException { + StackTraceElement[] stackTrace = throwable.getStackTrace(); + out.writeVInt(stackTrace.length); + for (StackTraceElement element : stackTrace) { + out.writeString(element.getClassName()); + out.writeString(element.getFileName()); + out.writeString(element.getMethodName()); + out.writeVInt(element.getLineNumber()); + } + Throwable[] suppressed = throwable.getSuppressed(); + out.writeVInt(suppressed.length); + for (Throwable t : suppressed) { + out.writeThrowable(t); + } + return throwable; + } + + static { + Class[] exceptions = new Class[]{ + org.elasticsearch.common.settings.SettingsException.class, + org.elasticsearch.index.snapshots.IndexShardSnapshotFailedException.class, + org.elasticsearch.index.engine.IndexFailedEngineException.class, + org.elasticsearch.indices.recovery.RecoverFilesRecoveryException.class, + org.elasticsearch.index.translog.TruncatedTranslogException.class, + org.elasticsearch.repositories.RepositoryException.class, + org.elasticsearch.index.shard.IndexShardException.class, + org.elasticsearch.index.engine.DocumentSourceMissingException.class, + org.elasticsearch.index.engine.DocumentMissingException.class, + org.elasticsearch.common.util.concurrent.EsRejectedExecutionException.class, + org.elasticsearch.cluster.routing.RoutingException.class, + org.elasticsearch.common.lucene.Lucene.EarlyTerminationException.class, + org.elasticsearch.indices.InvalidAliasNameException.class, + org.elasticsearch.index.engine.EngineCreationFailureException.class, + org.elasticsearch.index.snapshots.IndexShardRestoreFailedException.class, + org.elasticsearch.script.groovy.GroovyScriptCompilationException.class, + org.elasticsearch.cluster.routing.RoutingValidationException.class, + org.elasticsearch.snapshots.SnapshotMissingException.class, + org.elasticsearch.index.shard.IndexShardRecoveryException.class, + org.elasticsearch.action.search.SearchPhaseExecutionException.class, + org.elasticsearch.common.util.concurrent.UncategorizedExecutionException.class, + org.elasticsearch.index.engine.SnapshotFailedEngineException.class, + org.elasticsearch.action.search.ReduceSearchPhaseException.class, + org.elasticsearch.action.RoutingMissingException.class, + org.elasticsearch.index.engine.DeleteFailedEngineException.class, + org.elasticsearch.indices.recovery.RecoveryFailedException.class, + org.elasticsearch.search.builder.SearchSourceBuilderException.class, + org.elasticsearch.index.engine.RefreshFailedEngineException.class, + org.elasticsearch.index.snapshots.IndexShardSnapshotException.class, + org.elasticsearch.search.query.QueryPhaseExecutionException.class, + org.elasticsearch.cluster.metadata.ProcessClusterEventTimeoutException.class, + org.elasticsearch.index.shard.IndexShardCreationException.class, + org.elasticsearch.index.percolator.PercolatorException.class, + org.elasticsearch.snapshots.ConcurrentSnapshotExecutionException.class, + org.elasticsearch.indices.IndexTemplateAlreadyExistsException.class, + org.elasticsearch.indices.InvalidIndexNameException.class, + org.elasticsearch.index.IndexException.class, + org.elasticsearch.indices.recovery.DelayRecoveryException.class, + org.elasticsearch.indices.AliasFilterParsingException.class, + org.elasticsearch.indices.InvalidIndexTemplateException.class, + org.elasticsearch.http.HttpException.class, + org.elasticsearch.index.shard.IndexShardNotRecoveringException.class, + org.elasticsearch.indices.IndexPrimaryShardNotAllocatedException.class, + org.elasticsearch.env.FailedToResolveConfigException.class, + org.elasticsearch.action.UnavailableShardsException.class, + org.elasticsearch.transport.ActionNotFoundTransportException.class, + org.elasticsearch.index.shard.TranslogRecoveryPerformer.BatchOperationException.class, + org.elasticsearch.ElasticsearchException.class, + org.elasticsearch.index.shard.IndexShardClosedException.class, + org.elasticsearch.client.transport.NoNodeAvailableException.class, + org.elasticsearch.cluster.block.ClusterBlockException.class, + org.elasticsearch.action.FailedNodeException.class, + org.elasticsearch.indices.TypeMissingException.class, + org.elasticsearch.index.IndexShardMissingException.class, + org.elasticsearch.indices.InvalidTypeNameException.class, + org.elasticsearch.transport.netty.SizeHeaderFrameDecoder.HttpOnTransportException.class, + org.elasticsearch.common.util.CancellableThreads.ExecutionCancelledException.class, + org.elasticsearch.snapshots.SnapshotCreationException.class, + org.elasticsearch.script.groovy.GroovyScriptExecutionException.class, + org.elasticsearch.indices.IndexTemplateMissingException.class, + org.elasticsearch.transport.NodeNotConnectedException.class, + org.elasticsearch.index.shard.IndexShardRecoveringException.class, + org.elasticsearch.index.shard.IndexShardStartedException.class, + org.elasticsearch.indices.IndexClosedException.class, + org.elasticsearch.repositories.RepositoryMissingException.class, + org.elasticsearch.search.warmer.IndexWarmerMissingException.class, + org.elasticsearch.percolator.PercolateException.class, + org.elasticsearch.index.engine.EngineException.class, + org.elasticsearch.script.expression.ExpressionScriptExecutionException.class, + org.elasticsearch.action.NoShardAvailableActionException.class, + org.elasticsearch.transport.ReceiveTimeoutTransportException.class, + org.elasticsearch.http.BindHttpException.class, + org.elasticsearch.transport.RemoteTransportException.class, + org.elasticsearch.index.shard.IndexShardRelocatedException.class, + org.elasticsearch.snapshots.InvalidSnapshotNameException.class, + org.elasticsearch.repositories.RepositoryVerificationException.class, + org.elasticsearch.search.SearchException.class, + org.elasticsearch.transport.ActionTransportException.class, + org.elasticsearch.common.settings.NoClassSettingsException.class, + org.elasticsearch.transport.NodeShouldNotConnectException.class, + org.elasticsearch.index.mapper.MapperParsingException.class, + org.elasticsearch.action.support.replication.TransportReplicationAction.RetryOnReplicaException.class, + org.elasticsearch.search.dfs.DfsPhaseExecutionException.class, + org.elasticsearch.index.engine.VersionConflictEngineException.class, + org.elasticsearch.snapshots.SnapshotRestoreException.class, + org.elasticsearch.script.Script.ScriptParseException.class, + org.elasticsearch.ElasticsearchGenerationException.class, + org.elasticsearch.action.TimestampParsingException.class, + org.elasticsearch.action.NoSuchNodeException.class, + org.elasticsearch.transport.BindTransportException.class, + org.elasticsearch.snapshots.SnapshotException.class, + org.elasticsearch.index.mapper.MapperException.class, + org.elasticsearch.transport.TransportException.class, + org.elasticsearch.search.SearchContextException.class, + org.elasticsearch.index.translog.TranslogCorruptedException.class, + org.elasticsearch.transport.TransportSerializationException.class, + org.elasticsearch.cluster.IncompatibleClusterStateVersionException.class, + org.elasticsearch.indices.IndexCreationException.class, + org.elasticsearch.index.mapper.MergeMappingException.class, + org.elasticsearch.transport.NotSerializableTransportException.class, + org.elasticsearch.ElasticsearchTimeoutException.class, + org.elasticsearch.search.SearchContextMissingException.class, + org.elasticsearch.transport.SendRequestTransportException.class, + org.elasticsearch.indices.IndexMissingException.class, + org.elasticsearch.index.IndexShardAlreadyExistsException.class, + org.elasticsearch.indices.IndexAlreadyExistsException.class, + org.elasticsearch.index.engine.DocumentAlreadyExistsException.class, + org.elasticsearch.transport.ConnectTransportException.class, + org.elasticsearch.gateway.GatewayException.class, + org.elasticsearch.script.ScriptException.class, + org.elasticsearch.script.expression.ExpressionScriptCompilationException.class, + org.elasticsearch.index.shard.IndexShardNotStartedException.class, + org.elasticsearch.index.mapper.StrictDynamicMappingException.class, + org.elasticsearch.index.engine.EngineClosedException.class, + org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesMissingException.class, + org.elasticsearch.transport.ResponseHandlerFailureTransportException.class, + org.elasticsearch.search.SearchParseException.class, + org.elasticsearch.search.fetch.FetchPhaseExecutionException.class, + org.elasticsearch.transport.NodeDisconnectedException.class, + org.elasticsearch.common.breaker.CircuitBreakingException.class, + org.elasticsearch.search.aggregations.AggregationInitializationException.class, + org.elasticsearch.search.aggregations.InvalidAggregationPathException.class, + org.elasticsearch.cluster.routing.IllegalShardRoutingStateException.class, + org.elasticsearch.index.engine.FlushFailedEngineException.class, + org.elasticsearch.index.AlreadyExpiredException.class, + org.elasticsearch.index.translog.TranslogException.class, + org.elasticsearch.index.engine.FlushNotAllowedEngineException.class, + org.elasticsearch.index.engine.RecoveryEngineException.class, + org.elasticsearch.common.blobstore.BlobStoreException.class, + org.elasticsearch.index.snapshots.IndexShardRestoreException.class, + org.elasticsearch.index.store.StoreException.class, + org.elasticsearch.index.query.QueryParsingException.class, + org.elasticsearch.action.support.replication.TransportReplicationAction.RetryOnPrimaryException.class, + org.elasticsearch.index.engine.DeleteByQueryFailedEngineException.class, + org.elasticsearch.index.engine.ForceMergeFailedEngineException.class, + org.elasticsearch.discovery.MasterNotDiscoveredException.class, + org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException.class, + org.elasticsearch.node.NodeClosedException.class, + org.elasticsearch.search.aggregations.AggregationExecutionException.class, + org.elasticsearch.ElasticsearchParseException.class, + org.elasticsearch.action.PrimaryMissingActionException.class, + org.elasticsearch.index.engine.CreateFailedEngineException.class, + org.elasticsearch.index.shard.IllegalIndexShardStateException.class + }; + Map> mapping = new HashMap<>(); + + for (Class e : exceptions) { + String name = e.getName(); + try { + Constructor constructor = e.getDeclaredConstructor(StreamInput.class); + if (constructor == null) { + throw new IllegalStateException(name + " has not StreamInput ctor"); + } + mapping.put(name, constructor); + } catch (NoSuchMethodException t) { + throw new RuntimeException("failed to register [" + name + "] ", t); + } + } + + MAPPING = Collections.unmodifiableMap(mapping); + } + } diff --git a/core/src/main/java/org/elasticsearch/ElasticsearchGenerationException.java b/core/src/main/java/org/elasticsearch/ElasticsearchGenerationException.java index 0325b123c8e..8701ba7c9b6 100644 --- a/core/src/main/java/org/elasticsearch/ElasticsearchGenerationException.java +++ b/core/src/main/java/org/elasticsearch/ElasticsearchGenerationException.java @@ -19,6 +19,10 @@ package org.elasticsearch; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + /** * A generic exception indicating failure to generate. * @@ -33,4 +37,8 @@ public class ElasticsearchGenerationException extends ElasticsearchException { public ElasticsearchGenerationException(String msg, Throwable cause) { super(msg, cause); } + + public ElasticsearchGenerationException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/ElasticsearchNullPointerException.java b/core/src/main/java/org/elasticsearch/ElasticsearchNullPointerException.java deleted file mode 100644 index 721bf055f9f..00000000000 --- a/core/src/main/java/org/elasticsearch/ElasticsearchNullPointerException.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch; - -/** - * - */ -public class ElasticsearchNullPointerException extends ElasticsearchException { - - public ElasticsearchNullPointerException() { - super(null); - } - - public ElasticsearchNullPointerException(String msg) { - super(msg); - } - - public ElasticsearchNullPointerException(String msg, Throwable cause) { - super(msg, cause); - } -} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/ElasticsearchParseException.java b/core/src/main/java/org/elasticsearch/ElasticsearchParseException.java index cc6d907054d..626d1162c04 100644 --- a/core/src/main/java/org/elasticsearch/ElasticsearchParseException.java +++ b/core/src/main/java/org/elasticsearch/ElasticsearchParseException.java @@ -19,8 +19,11 @@ package org.elasticsearch; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ @@ -34,6 +37,9 @@ public class ElasticsearchParseException extends ElasticsearchException { super(msg, cause); } + public ElasticsearchParseException(StreamInput in) throws IOException { + super(in); + } @Override public RestStatus status() { return RestStatus.BAD_REQUEST; diff --git a/core/src/main/java/org/elasticsearch/ElasticsearchTimeoutException.java b/core/src/main/java/org/elasticsearch/ElasticsearchTimeoutException.java index a5e81896154..7860046e6ab 100644 --- a/core/src/main/java/org/elasticsearch/ElasticsearchTimeoutException.java +++ b/core/src/main/java/org/elasticsearch/ElasticsearchTimeoutException.java @@ -19,12 +19,19 @@ package org.elasticsearch; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + /** * The same as {@link java.util.concurrent.TimeoutException} simply a runtime one. * * */ public class ElasticsearchTimeoutException extends ElasticsearchException { + public ElasticsearchTimeoutException(StreamInput in) throws IOException { + super(in); + } public ElasticsearchTimeoutException(String message) { super(message); diff --git a/core/src/main/java/org/elasticsearch/action/FailedNodeException.java b/core/src/main/java/org/elasticsearch/action/FailedNodeException.java index 7e9857fbb06..f6e680f2dab 100644 --- a/core/src/main/java/org/elasticsearch/action/FailedNodeException.java +++ b/core/src/main/java/org/elasticsearch/action/FailedNodeException.java @@ -20,6 +20,10 @@ package org.elasticsearch.action; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; /** * @@ -36,4 +40,15 @@ public class FailedNodeException extends ElasticsearchException { public String nodeId() { return this.nodeId; } + + public FailedNodeException(StreamInput in) throws IOException { + super(in); + nodeId = in.readOptionalString(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeOptionalString(nodeId); + } } diff --git a/core/src/main/java/org/elasticsearch/action/NoShardAvailableActionException.java b/core/src/main/java/org/elasticsearch/action/NoShardAvailableActionException.java index 5c06cff2b8d..3ab5869045f 100644 --- a/core/src/main/java/org/elasticsearch/action/NoShardAvailableActionException.java +++ b/core/src/main/java/org/elasticsearch/action/NoShardAvailableActionException.java @@ -19,10 +19,13 @@ package org.elasticsearch.action; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ @@ -44,4 +47,8 @@ public class NoShardAvailableActionException extends IndexShardException { public RestStatus status() { return RestStatus.SERVICE_UNAVAILABLE; } + + public NoShardAvailableActionException(StreamInput in) throws IOException{ + super(in); + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/action/NoSuchNodeException.java b/core/src/main/java/org/elasticsearch/action/NoSuchNodeException.java index fb5699baab9..a3e7474ea6b 100644 --- a/core/src/main/java/org/elasticsearch/action/NoSuchNodeException.java +++ b/core/src/main/java/org/elasticsearch/action/NoSuchNodeException.java @@ -19,6 +19,11 @@ package org.elasticsearch.action; +import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + /** * */ @@ -27,4 +32,8 @@ public class NoSuchNodeException extends FailedNodeException { public NoSuchNodeException(String nodeId) { super(nodeId, "No such node [" + nodeId + "]", null); } + + public NoSuchNodeException(StreamInput in) throws IOException { + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/action/PrimaryMissingActionException.java b/core/src/main/java/org/elasticsearch/action/PrimaryMissingActionException.java index bc75ce36a94..f364bdb9aef 100644 --- a/core/src/main/java/org/elasticsearch/action/PrimaryMissingActionException.java +++ b/core/src/main/java/org/elasticsearch/action/PrimaryMissingActionException.java @@ -20,6 +20,9 @@ package org.elasticsearch.action; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * @@ -29,4 +32,8 @@ public class PrimaryMissingActionException extends ElasticsearchException { public PrimaryMissingActionException(String message) { super(message); } + + public PrimaryMissingActionException(StreamInput in) throws IOException { + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/action/RoutingMissingException.java b/core/src/main/java/org/elasticsearch/action/RoutingMissingException.java index 58cd7e9c35a..f5ed1f54aff 100644 --- a/core/src/main/java/org/elasticsearch/action/RoutingMissingException.java +++ b/core/src/main/java/org/elasticsearch/action/RoutingMissingException.java @@ -20,8 +20,12 @@ package org.elasticsearch.action; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ @@ -56,4 +60,19 @@ public class RoutingMissingException extends ElasticsearchException { public RestStatus status() { return RestStatus.BAD_REQUEST; } + + public RoutingMissingException(StreamInput in) throws IOException{ + super(in); + index = in.readString(); + type = in.readString(); + id = in.readString(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeString(index); + out.writeString(type); + out.writeString(id); + } } diff --git a/core/src/main/java/org/elasticsearch/action/TimestampParsingException.java b/core/src/main/java/org/elasticsearch/action/TimestampParsingException.java index d865483a6ac..0764bb502c0 100644 --- a/core/src/main/java/org/elasticsearch/action/TimestampParsingException.java +++ b/core/src/main/java/org/elasticsearch/action/TimestampParsingException.java @@ -20,6 +20,10 @@ package org.elasticsearch.action; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; /** */ @@ -40,4 +44,15 @@ public class TimestampParsingException extends ElasticsearchException { public String timestamp() { return timestamp; } + + public TimestampParsingException(StreamInput in) throws IOException{ + super(in); + this.timestamp = in.readOptionalString(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeOptionalString(timestamp); + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/action/UnavailableShardsException.java b/core/src/main/java/org/elasticsearch/action/UnavailableShardsException.java index dcc6f04ab74..dd0968ee4ea 100644 --- a/core/src/main/java/org/elasticsearch/action/UnavailableShardsException.java +++ b/core/src/main/java/org/elasticsearch/action/UnavailableShardsException.java @@ -21,9 +21,12 @@ package org.elasticsearch.action; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ @@ -40,6 +43,10 @@ public class UnavailableShardsException extends ElasticsearchException { return "[" + shardId.index().name() + "][" + shardId.id() + "] " + message; } + public UnavailableShardsException(StreamInput in) throws IOException { + super(in); + } + @Override public RestStatus status() { return RestStatus.SERVICE_UNAVAILABLE; diff --git a/core/src/main/java/org/elasticsearch/action/search/ReduceSearchPhaseException.java b/core/src/main/java/org/elasticsearch/action/search/ReduceSearchPhaseException.java index 84398ba92f1..e01788dcc12 100644 --- a/core/src/main/java/org/elasticsearch/action/search/ReduceSearchPhaseException.java +++ b/core/src/main/java/org/elasticsearch/action/search/ReduceSearchPhaseException.java @@ -19,6 +19,10 @@ package org.elasticsearch.action.search; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + /** * A failure during a reduce phase (when receiving results from several shards, and reducing them * into one or more results and possible actions). @@ -27,11 +31,11 @@ package org.elasticsearch.action.search; */ public class ReduceSearchPhaseException extends SearchPhaseExecutionException { - public ReduceSearchPhaseException(String phaseName, String msg, ShardSearchFailure[] shardFailures) { - super(phaseName, "[reduce] " + msg, shardFailures); - } - public ReduceSearchPhaseException(String phaseName, String msg, Throwable cause, ShardSearchFailure[] shardFailures) { super(phaseName, "[reduce] " + msg, cause, shardFailures); } + + public ReduceSearchPhaseException(StreamInput in) throws IOException { + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java b/core/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java index c1ab2d6bfb2..4821cade3a2 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java @@ -22,6 +22,8 @@ package org.elasticsearch.action.search; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.ShardOperationFailedException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexException; @@ -36,7 +38,7 @@ import java.util.*; public class SearchPhaseExecutionException extends ElasticsearchException { private final String phaseName; - private ShardSearchFailure[] shardFailures; + private final ShardSearchFailure[] shardFailures; public SearchPhaseExecutionException(String phaseName, String msg, ShardSearchFailure[] shardFailures) { super(msg); @@ -50,6 +52,28 @@ public class SearchPhaseExecutionException extends ElasticsearchException { this.shardFailures = shardFailures; } + public SearchPhaseExecutionException(StreamInput in) throws IOException { + super(in); + phaseName = in.readOptionalString(); + int numFailures = in.readVInt(); + shardFailures = new ShardSearchFailure[numFailures]; + for (int i = 0; i < numFailures; i++) { + shardFailures[i] = ShardSearchFailure.readShardSearchFailure(in); + } + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeOptionalString(phaseName); + out.writeVInt(shardFailures == null ? 0 : shardFailures.length); + if (shardFailures != null) { + for (ShardSearchFailure failure : shardFailures) { + failure.writeTo(out); + } + } + } + @Override public RestStatus status() { if (shardFailures.length == 0) { diff --git a/core/src/main/java/org/elasticsearch/action/support/HandledTransportAction.java b/core/src/main/java/org/elasticsearch/action/support/HandledTransportAction.java index e2e1072feb3..001b410842e 100644 --- a/core/src/main/java/org/elasticsearch/action/support/HandledTransportAction.java +++ b/core/src/main/java/org/elasticsearch/action/support/HandledTransportAction.java @@ -56,8 +56,8 @@ public abstract class HandledTransportAction builder = ImmutableSet.builder(); + for (int i = 0; i < num; i++) { + builder.add(ClusterBlock.readClusterBlock(in)); + } + blocks = builder.build(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + if (blocks != null) { + out.writeVInt(blocks.size()); + for (ClusterBlock block : blocks) { + block.writeTo(out); + } + } else { + out.writeVInt(0); + } + } + public boolean retryable() { for (ClusterBlock block : blocks) { if (!block.retryable()) { diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/ProcessClusterEventTimeoutException.java b/core/src/main/java/org/elasticsearch/cluster/metadata/ProcessClusterEventTimeoutException.java index 38fc3f72a5d..f161f8c55ee 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/ProcessClusterEventTimeoutException.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/ProcessClusterEventTimeoutException.java @@ -20,9 +20,12 @@ package org.elasticsearch.cluster.metadata; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** */ public class ProcessClusterEventTimeoutException extends ElasticsearchException { @@ -31,6 +34,10 @@ public class ProcessClusterEventTimeoutException extends ElasticsearchException super("failed to process cluster event (" + source + ") within " + timeValue); } + public ProcessClusterEventTimeoutException(StreamInput in) throws IOException { + super(in); + } + @Override public RestStatus status() { return RestStatus.SERVICE_UNAVAILABLE; diff --git a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java index 915f0d5599d..8a8cd819c40 100644 --- a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -39,7 +39,7 @@ import static org.elasticsearch.common.transport.TransportAddressSerializers.add /** * A discovery node represents a node that is part of the cluster. */ -public class DiscoveryNode implements Streamable, Serializable { +public class DiscoveryNode implements Streamable { /** * Minimum version of a node to communicate with. This version corresponds to the minimum compatibility version @@ -373,19 +373,4 @@ public class DiscoveryNode implements Streamable, Serializable { } return sb.toString(); } - - // we need this custom serialization logic because Version is not serializable (because org.apache.lucene.util.Version is not serializable) - private void writeObject(java.io.ObjectOutputStream out) - throws IOException { - StreamOutput streamOutput = new OutputStreamStreamOutput(out); - streamOutput.setVersion(Version.CURRENT.minimumCompatibilityVersion()); - this.writeTo(streamOutput); - } - - private void readObject(java.io.ObjectInputStream in) - throws IOException, ClassNotFoundException { - StreamInput streamInput = new InputStreamStreamInput(in); - streamInput.setVersion(Version.CURRENT.minimumCompatibilityVersion()); - this.readFrom(streamInput); - } } diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/IllegalShardRoutingStateException.java b/core/src/main/java/org/elasticsearch/cluster/routing/IllegalShardRoutingStateException.java index d2b395b86bc..af1d4195075 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/IllegalShardRoutingStateException.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/IllegalShardRoutingStateException.java @@ -19,6 +19,11 @@ package org.elasticsearch.cluster.routing; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; + /** * This exception defines illegal states of shard routing */ @@ -35,6 +40,17 @@ public class IllegalShardRoutingStateException extends RoutingException { this.shard = shard; } + public IllegalShardRoutingStateException(StreamInput in) throws IOException { + super(in); + shard = ShardRouting.readShardRoutingEntry(in); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + shard.writeTo(out); + } + /** * Returns the shard instance referenced by this exception * @return shard instance referenced by this exception diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingException.java b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingException.java index c5c7652b866..748fe3d9c4e 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingException.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingException.java @@ -20,6 +20,9 @@ package org.elasticsearch.cluster.routing; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * A base {@link Exception}s for all exceptions thrown by routing related operations. @@ -33,4 +36,8 @@ public class RoutingException extends ElasticsearchException { public RoutingException(String message, Throwable cause) { super(message, cause); } + + public RoutingException(StreamInput in) throws IOException{ + super(in); + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingValidationException.java b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingValidationException.java index 691b4aa2f61..63af66f688d 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingValidationException.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingValidationException.java @@ -19,6 +19,11 @@ package org.elasticsearch.cluster.routing; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; + /** * This class defines {@link RoutingException}s related to * the validation of routing @@ -32,6 +37,17 @@ public class RoutingValidationException extends RoutingException { this.validation = validation; } + public RoutingValidationException(StreamInput in) throws IOException { + super(in); + validation = in.readOptionalStreamable(new RoutingTableValidation()); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeOptionalStreamable(validation); + } + public RoutingTableValidation validation() { return this.validation; } diff --git a/core/src/main/java/org/elasticsearch/common/Base64.java b/core/src/main/java/org/elasticsearch/common/Base64.java index 81dbaf522d4..c1b63d09e4f 100644 --- a/core/src/main/java/org/elasticsearch/common/Base64.java +++ b/core/src/main/java/org/elasticsearch/common/Base64.java @@ -632,116 +632,6 @@ public class Base64 { } - /** - * Serializes an object and returns the Base64-encoded - * version of that serialized object. - *

- *

As of v 2.3, if the object - * cannot be serialized or there is another error, - * the method will throw an java.io.IOException. This is new to v2.3! - * In earlier versions, it just returned a null value, but - * in retrospect that's a pretty poor way to handle it.

- *

- * The object is not GZip-compressed before being encoded. - * - * @param serializableObject The object to encode - * @return The Base64-encoded object - * @throws java.io.IOException if there is an error - * @throws NullPointerException if serializedObject is null - * @since 1.4 - */ - public static String encodeObject(java.io.Serializable serializableObject) - throws java.io.IOException { - return encodeObject(serializableObject, NO_OPTIONS); - } // end encodeObject - - - /** - * Serializes an object and returns the Base64-encoded - * version of that serialized object. - *

- *

As of v 2.3, if the object - * cannot be serialized or there is another error, - * the method will throw an java.io.IOException. This is new to v2.3! - * In earlier versions, it just returned a null value, but - * in retrospect that's a pretty poor way to handle it.

- *

- * The object is not GZip-compressed before being encoded. - *

- * Example options:

-     *   GZIP: gzip-compresses object before encoding it.
-     *   DO_BREAK_LINES: break lines at 76 characters
-     * 
- *

- * Example: encodeObject( myObj, Base64.GZIP ) or - *

- * Example: encodeObject( myObj, Base64.GZIP | Base64.DO_BREAK_LINES ) - * - * @param serializableObject The object to encode - * @param options Specified options - * @return The Base64-encoded object - * @throws java.io.IOException if there is an error - * @see Base64#GZIP - * @see Base64#DO_BREAK_LINES - * @since 2.0 - */ - public static String encodeObject(java.io.Serializable serializableObject, int options) - throws java.io.IOException { - - if (serializableObject == null) { - throw new NullPointerException("Cannot serialize a null object."); - } // end if: null - - // Streams - java.io.ByteArrayOutputStream baos = null; - java.io.OutputStream b64os = null; - java.util.zip.GZIPOutputStream gzos = null; - java.io.ObjectOutputStream oos = null; - - - try { - // ObjectOutputStream -> (GZIP) -> Base64 -> ByteArrayOutputStream - baos = new java.io.ByteArrayOutputStream(); - b64os = new Base64.OutputStream(baos, ENCODE | options); - if ((options & GZIP) != 0) { - // Gzip - gzos = new java.util.zip.GZIPOutputStream(b64os); - oos = new java.io.ObjectOutputStream(gzos); - } else { - // Not gzipped - oos = new java.io.ObjectOutputStream(b64os); - } - oos.writeObject(serializableObject); - } // end try - catch (java.io.IOException e) { - // Catch it and then throw it immediately so that - // the finally{} block is called for cleanup. - throw e; - } // end catch - finally { - try { - oos.close(); - } catch (Exception e) { - } - try { - gzos.close(); - } catch (Exception e) { - } - try { - b64os.close(); - } catch (Exception e) { - } - try { - baos.close(); - } catch (Exception e) { - } - } // end finally - - // Return value according to relevant encoding. - return new String(baos.toByteArray(), PREFERRED_ENCODING); - - } // end encode - /** * Encodes a byte array into Base64 notation. @@ -799,7 +689,6 @@ public class Base64 { return encodeBytes(source, 0, source.length, options); } // end encodeBytes - /** * Encodes a byte array into Base64 notation. * Does not GZip-compress data. diff --git a/core/src/main/java/org/elasticsearch/common/blobstore/BlobStoreException.java b/core/src/main/java/org/elasticsearch/common/blobstore/BlobStoreException.java index 6be245858c0..4d982b3c3e3 100644 --- a/core/src/main/java/org/elasticsearch/common/blobstore/BlobStoreException.java +++ b/core/src/main/java/org/elasticsearch/common/blobstore/BlobStoreException.java @@ -20,6 +20,9 @@ package org.elasticsearch.common.blobstore; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * @@ -33,4 +36,8 @@ public class BlobStoreException extends ElasticsearchException { public BlobStoreException(String msg, Throwable cause) { super(msg, cause); } + + public BlobStoreException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/common/breaker/CircuitBreakingException.java b/core/src/main/java/org/elasticsearch/common/breaker/CircuitBreakingException.java index 0b88a9dad7c..d35bac1f3d0 100644 --- a/core/src/main/java/org/elasticsearch/common/breaker/CircuitBreakingException.java +++ b/core/src/main/java/org/elasticsearch/common/breaker/CircuitBreakingException.java @@ -19,6 +19,10 @@ package org.elasticsearch.common.breaker; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; /** * Exception thrown when the circuit breaker trips @@ -34,12 +38,25 @@ public class CircuitBreakingException extends ElasticsearchException { this.byteLimit = 0; } + public CircuitBreakingException(StreamInput in) throws IOException { + super(in); + byteLimit = in.readLong(); + bytesWanted = in.readLong(); + } + public CircuitBreakingException(String message, long bytesWanted, long byteLimit) { super(message); this.bytesWanted = bytesWanted; this.byteLimit = byteLimit; } + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeLong(byteLimit); + out.writeLong(bytesWanted); + } + public long getBytesWanted() { return this.bytesWanted; } diff --git a/core/src/main/java/org/elasticsearch/common/io/ThrowableObjectInputStream.java b/core/src/main/java/org/elasticsearch/common/io/ThrowableObjectInputStream.java deleted file mode 100644 index b1dffd6d157..00000000000 --- a/core/src/main/java/org/elasticsearch/common/io/ThrowableObjectInputStream.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.common.io; - -import org.elasticsearch.common.Classes; - -import java.io.*; - -/** - * - */ -public class ThrowableObjectInputStream extends ObjectInputStream { - - private final ClassLoader classLoader; - - public ThrowableObjectInputStream(InputStream in) throws IOException { - this(in, null); - } - - public ThrowableObjectInputStream(InputStream in, ClassLoader classLoader) throws IOException { - super(in); - this.classLoader = classLoader; - } - - @Override - protected void readStreamHeader() throws IOException, StreamCorruptedException { - int version = readByte() & 0xFF; - if (version != STREAM_VERSION) { - throw new StreamCorruptedException( - "Unsupported version: " + version); - } - } - - @Override - protected ObjectStreamClass readClassDescriptor() - throws IOException, ClassNotFoundException { - int type = read(); - if (type < 0) { - throw new EOFException(); - } - switch (type) { - case ThrowableObjectOutputStream.TYPE_EXCEPTION: - return ObjectStreamClass.lookup(Exception.class); - case ThrowableObjectOutputStream.TYPE_STACKTRACEELEMENT: - return ObjectStreamClass.lookup(StackTraceElement.class); - case ThrowableObjectOutputStream.TYPE_FAT_DESCRIPTOR: - return super.readClassDescriptor(); - case ThrowableObjectOutputStream.TYPE_THIN_DESCRIPTOR: - String className = readUTF(); - Class clazz = loadClass(className); - return ObjectStreamClass.lookup(clazz); - default: - throw new StreamCorruptedException( - "Unexpected class descriptor type: " + type); - } - } - - @Override - protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { - String className = desc.getName(); - try { - return loadClass(className); - } catch (ClassNotFoundException ex) { - return super.resolveClass(desc); - } - } - - protected Class loadClass(String className) throws ClassNotFoundException { - Class clazz; - ClassLoader classLoader = this.classLoader; - if (classLoader == null) { - classLoader = Classes.getDefaultClassLoader(); - } - - if (classLoader != null) { - clazz = classLoader.loadClass(className); - } else { - clazz = Class.forName(className); - } - return clazz; - } -} diff --git a/core/src/main/java/org/elasticsearch/common/io/ThrowableObjectOutputStream.java b/core/src/main/java/org/elasticsearch/common/io/ThrowableObjectOutputStream.java deleted file mode 100644 index 282b2904dc3..00000000000 --- a/core/src/main/java/org/elasticsearch/common/io/ThrowableObjectOutputStream.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.common.io; - -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.io.ObjectStreamClass; -import java.io.OutputStream; - -/** - * - */ -public class ThrowableObjectOutputStream extends ObjectOutputStream { - - static final int TYPE_FAT_DESCRIPTOR = 0; - static final int TYPE_THIN_DESCRIPTOR = 1; - - private static final String EXCEPTION_CLASSNAME = Exception.class.getName(); - static final int TYPE_EXCEPTION = 2; - - private static final String STACKTRACEELEMENT_CLASSNAME = StackTraceElement.class.getName(); - static final int TYPE_STACKTRACEELEMENT = 3; - - - public ThrowableObjectOutputStream(OutputStream out) throws IOException { - super(out); - } - - @Override - protected void writeStreamHeader() throws IOException { - writeByte(STREAM_VERSION); - } - - @Override - protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException { - if (desc.getName().equals(EXCEPTION_CLASSNAME)) { - write(TYPE_EXCEPTION); - } else if (desc.getName().equals(STACKTRACEELEMENT_CLASSNAME)) { - write(TYPE_STACKTRACEELEMENT); - } else { - Class clazz = desc.forClass(); - if (clazz.isPrimitive() || clazz.isArray()) { - write(TYPE_FAT_DESCRIPTOR); - super.writeClassDescriptor(desc); - } else { - write(TYPE_THIN_DESCRIPTOR); - writeUTF(desc.getName()); - } - } - } -} diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java index 4d3def161cd..5b7d4a4143a 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java @@ -19,8 +19,12 @@ package org.elasticsearch.common.io.stream; +import org.apache.lucene.index.CorruptIndexException; +import org.apache.lucene.index.IndexFormatTooNewException; +import org.apache.lucene.index.IndexFormatTooOldException; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.CharsRefBuilder; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; @@ -31,11 +35,9 @@ import org.elasticsearch.common.text.Text; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; +import java.io.*; import java.util.*; +import java.util.regex.Pattern; /** * @@ -480,12 +482,51 @@ public abstract class StreamInput extends InputStream { } public T readThrowable() throws IOException { - try { - ObjectInputStream oin = new ObjectInputStream(this); - return (T) oin.readObject(); - } catch (ClassNotFoundException e) { - throw new IOException("failed to deserialize exception", e); + if (readBoolean()) { + int key = readVInt(); + switch (key) { + case 0: + return (T) ElasticsearchException.readException(this); + case 1: + // nocommit - this sucks it would be nice to have a better way to construct those? + String msg = readOptionalString(); + final int idx = msg.indexOf(" (resource="); + String resource = msg.substring(idx + " (resource=".length(), msg.length()-1); + msg = msg.substring(0, idx); + return (T) ElasticsearchException.readStackTrace(new CorruptIndexException(msg, resource, readThrowable()), this); // TODO add a string throwable ctor to this? + case 2: + String itnMessage = readOptionalString(); + readThrowable(); + return (T) ElasticsearchException.readStackTrace(new IndexFormatTooNewException(itnMessage, -1, -1, -1), this); + case 3: + String itoMessage = readOptionalString(); + readThrowable(); + return (T) ElasticsearchException.readStackTrace(new IndexFormatTooOldException(itoMessage, -1, -1, -1), this); + case 4: + String npeMessage = readOptionalString(); + readThrowable(); + return (T) ElasticsearchException.readStackTrace(new NullPointerException(npeMessage), this); + case 5: + String nfeMessage = readOptionalString(); + readThrowable(); + return (T) ElasticsearchException.readStackTrace(new NumberFormatException(nfeMessage), this); + case 6: + return (T) ElasticsearchException.readStackTrace(new IllegalArgumentException(readOptionalString(), readThrowable()), this); + case 7: + return (T) ElasticsearchException.readStackTrace(new IllegalStateException(readOptionalString(), readThrowable()), this); + case 8: + String eofMessage = readOptionalString(); + readThrowable(); + return (T) ElasticsearchException.readStackTrace(new EOFException(eofMessage), this); + case 9: + return (T) ElasticsearchException.readStackTrace(new SecurityException(readOptionalString(), readThrowable()), this); + case 10: // unknown -- // nocommit - should we use a dedicated exception + return (T) ElasticsearchException.readStackTrace(new ElasticsearchException(readOptionalString(), readThrowable()), this); + default: + assert false : "no such exception for id: " + key; + } } + return null; } public static StreamInput wrap(BytesReference reference) { @@ -502,4 +543,5 @@ public abstract class StreamInput extends InputStream { public static StreamInput wrap(byte[] bytes, int offset, int length) { return new InputStreamStreamInput(new ByteArrayInputStream(bytes, offset, length)); } + } diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java index 6d0b40c97f6..a98371acc97 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java @@ -19,14 +19,20 @@ package org.elasticsearch.common.io.stream; +import org.apache.lucene.index.CorruptIndexException; +import org.apache.lucene.index.IndexFormatTooNewException; +import org.apache.lucene.index.IndexFormatTooOldException; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; +import org.elasticsearch.bootstrap.Elasticsearch; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.text.Text; import org.joda.time.ReadableInstant; +import java.io.EOFException; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.OutputStream; @@ -445,8 +451,38 @@ public abstract class StreamOutput extends OutputStream { } public void writeThrowable(Throwable throwable) throws IOException { - ObjectOutputStream out = new ObjectOutputStream(this); - out.writeObject(throwable); - out.flush(); + if (throwable == null) { + writeBoolean(false); + } else { + writeBoolean(true); + if (throwable instanceof ElasticsearchException) { + writeVInt(0); + ElasticsearchException.writeException((ElasticsearchException) throwable, this); + return; + } else if (throwable instanceof CorruptIndexException) { + writeVInt(1); + } else if (throwable instanceof IndexFormatTooNewException) { + writeVInt(2); + } else if (throwable instanceof IndexFormatTooOldException) { + writeVInt(3); + } else if (throwable instanceof NullPointerException) { + writeVInt(4); + } else if (throwable instanceof NumberFormatException) { + writeVInt(5); + } else if (throwable instanceof IllegalArgumentException) { + writeVInt(6); + } else if (throwable instanceof IllegalStateException) { + writeVInt(7); + } else if (throwable instanceof EOFException) { + writeVInt(8); + } else if (throwable instanceof SecurityException) { + writeVInt(9); + } else { + writeVInt(10); // unknown + } + writeOptionalString(throwable.getMessage()); + writeThrowable(throwable.getCause()); + ElasticsearchException.writeStackTraces(throwable, this); + } } } diff --git a/core/src/main/java/org/elasticsearch/common/lucene/Lucene.java b/core/src/main/java/org/elasticsearch/common/lucene/Lucene.java index 7154f83c71d..031a1498898 100644 --- a/core/src/main/java/org/elasticsearch/common/lucene/Lucene.java +++ b/core/src/main/java/org/elasticsearch/common/lucene/Lucene.java @@ -604,6 +604,10 @@ public class Lucene { public EarlyTerminationException(String msg) { super(msg); } + + public EarlyTerminationException(StreamInput in) throws IOException{ + super(in); + } } /** diff --git a/core/src/main/java/org/elasticsearch/common/settings/NoClassSettingsException.java b/core/src/main/java/org/elasticsearch/common/settings/NoClassSettingsException.java index dbeeaadb473..d8bda48c58d 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/NoClassSettingsException.java +++ b/core/src/main/java/org/elasticsearch/common/settings/NoClassSettingsException.java @@ -19,6 +19,10 @@ package org.elasticsearch.common.settings; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + /** * A specific type of {@link SettingsException} indicating failure to load a class * based on a settings value. @@ -27,11 +31,11 @@ package org.elasticsearch.common.settings; */ public class NoClassSettingsException extends SettingsException { - public NoClassSettingsException(String message) { - super(message); - } - public NoClassSettingsException(String message, Throwable cause) { super(message, cause); } + + public NoClassSettingsException(StreamInput in) throws IOException { + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/common/settings/SettingsException.java b/core/src/main/java/org/elasticsearch/common/settings/SettingsException.java index 9a4576f62e5..f7d4843c1c0 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/SettingsException.java +++ b/core/src/main/java/org/elasticsearch/common/settings/SettingsException.java @@ -20,6 +20,9 @@ package org.elasticsearch.common.settings; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * A generic failure to handle settings. @@ -35,4 +38,8 @@ public class SettingsException extends ElasticsearchException { public SettingsException(String message, Throwable cause) { super(message, cause); } + + public SettingsException(StreamInput in) throws IOException { + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/common/transport/InetSocketTransportAddress.java b/core/src/main/java/org/elasticsearch/common/transport/InetSocketTransportAddress.java index bfa4233d917..027f42a58cd 100644 --- a/core/src/main/java/org/elasticsearch/common/transport/InetSocketTransportAddress.java +++ b/core/src/main/java/org/elasticsearch/common/transport/InetSocketTransportAddress.java @@ -60,12 +60,6 @@ public class InetSocketTransportAddress implements TransportAddress { this.address = address; } - public static InetSocketTransportAddress readInetSocketTransportAddress(StreamInput in) throws IOException { - InetSocketTransportAddress address = new InetSocketTransportAddress(); - address.readFrom(in); - return address; - } - @Override public short uniqueAddressTypeId() { return 1; diff --git a/core/src/main/java/org/elasticsearch/common/transport/TransportAddress.java b/core/src/main/java/org/elasticsearch/common/transport/TransportAddress.java index e9f7ac01774..5bff0f9fdaa 100644 --- a/core/src/main/java/org/elasticsearch/common/transport/TransportAddress.java +++ b/core/src/main/java/org/elasticsearch/common/transport/TransportAddress.java @@ -26,7 +26,7 @@ import java.io.Serializable; /** * */ -public interface TransportAddress extends Streamable, Serializable { +public interface TransportAddress extends Streamable { short uniqueAddressTypeId(); diff --git a/core/src/main/java/org/elasticsearch/common/util/CancellableThreads.java b/core/src/main/java/org/elasticsearch/common/util/CancellableThreads.java index 23313de5172..67b844bf7a1 100644 --- a/core/src/main/java/org/elasticsearch/common/util/CancellableThreads.java +++ b/core/src/main/java/org/elasticsearch/common/util/CancellableThreads.java @@ -20,7 +20,9 @@ package org.elasticsearch.common.util; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.io.stream.StreamInput; +import java.io.IOException; import java.util.HashSet; import java.util.Set; @@ -132,14 +134,14 @@ public class CancellableThreads { public void run() throws InterruptedException; } - public class ExecutionCancelledException extends ElasticsearchException { + public static class ExecutionCancelledException extends ElasticsearchException { public ExecutionCancelledException(String msg) { super(msg); } - public ExecutionCancelledException(String msg, Throwable cause) { - super(msg, cause); + public ExecutionCancelledException(StreamInput in) throws IOException { + super(in); } } } diff --git a/core/src/main/java/org/elasticsearch/common/util/concurrent/EsRejectedExecutionException.java b/core/src/main/java/org/elasticsearch/common/util/concurrent/EsRejectedExecutionException.java index 7c5e7812089..2aec22c04ec 100644 --- a/core/src/main/java/org/elasticsearch/common/util/concurrent/EsRejectedExecutionException.java +++ b/core/src/main/java/org/elasticsearch/common/util/concurrent/EsRejectedExecutionException.java @@ -20,8 +20,11 @@ package org.elasticsearch.common.util.concurrent; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** */ public class EsRejectedExecutionException extends ElasticsearchException { @@ -31,7 +34,7 @@ public class EsRejectedExecutionException extends ElasticsearchException { } public EsRejectedExecutionException() { - super(null); + super((String)null); } public EsRejectedExecutionException(Throwable e) { @@ -42,4 +45,8 @@ public class EsRejectedExecutionException extends ElasticsearchException { public RestStatus status() { return RestStatus.TOO_MANY_REQUESTS; } + + public EsRejectedExecutionException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/common/util/concurrent/UncategorizedExecutionException.java b/core/src/main/java/org/elasticsearch/common/util/concurrent/UncategorizedExecutionException.java index 89b71b60d57..a74a1a073f8 100644 --- a/core/src/main/java/org/elasticsearch/common/util/concurrent/UncategorizedExecutionException.java +++ b/core/src/main/java/org/elasticsearch/common/util/concurrent/UncategorizedExecutionException.java @@ -20,6 +20,9 @@ package org.elasticsearch.common.util.concurrent; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * @@ -29,4 +32,8 @@ public class UncategorizedExecutionException extends ElasticsearchException { public UncategorizedExecutionException(String msg, Throwable cause) { super(msg, cause); } + + public UncategorizedExecutionException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/discovery/MasterNotDiscoveredException.java b/core/src/main/java/org/elasticsearch/discovery/MasterNotDiscoveredException.java index b2b4e93556b..90964204a81 100644 --- a/core/src/main/java/org/elasticsearch/discovery/MasterNotDiscoveredException.java +++ b/core/src/main/java/org/elasticsearch/discovery/MasterNotDiscoveredException.java @@ -20,8 +20,11 @@ package org.elasticsearch.discovery; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ @@ -39,4 +42,8 @@ public class MasterNotDiscoveredException extends ElasticsearchException { public RestStatus status() { return RestStatus.SERVICE_UNAVAILABLE; } + + public MasterNotDiscoveredException(StreamInput in) throws IOException { + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/env/FailedToResolveConfigException.java b/core/src/main/java/org/elasticsearch/env/FailedToResolveConfigException.java index e6b2a82c9dd..f61ac3ec7ae 100644 --- a/core/src/main/java/org/elasticsearch/env/FailedToResolveConfigException.java +++ b/core/src/main/java/org/elasticsearch/env/FailedToResolveConfigException.java @@ -20,6 +20,9 @@ package org.elasticsearch.env; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * @@ -33,4 +36,8 @@ public class FailedToResolveConfigException extends ElasticsearchException { public FailedToResolveConfigException(String msg, Throwable cause) { super(msg, cause); } + + public FailedToResolveConfigException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/gateway/GatewayException.java b/core/src/main/java/org/elasticsearch/gateway/GatewayException.java index 498808d3242..619d3d5f41e 100644 --- a/core/src/main/java/org/elasticsearch/gateway/GatewayException.java +++ b/core/src/main/java/org/elasticsearch/gateway/GatewayException.java @@ -20,6 +20,9 @@ package org.elasticsearch.gateway; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * @@ -33,4 +36,8 @@ public class GatewayException extends ElasticsearchException { public GatewayException(String msg, Throwable cause) { super(msg, cause); } + + public GatewayException(StreamInput in) throws IOException { + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/http/BindHttpException.java b/core/src/main/java/org/elasticsearch/http/BindHttpException.java index 3fdad9ca79c..ebfc7e768eb 100644 --- a/core/src/main/java/org/elasticsearch/http/BindHttpException.java +++ b/core/src/main/java/org/elasticsearch/http/BindHttpException.java @@ -19,16 +19,20 @@ package org.elasticsearch.http; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + /** * */ public class BindHttpException extends HttpException { - public BindHttpException(String message) { - super(message); - } - public BindHttpException(String message, Throwable cause) { super(message, cause); } + + public BindHttpException(StreamInput in) throws IOException { + super(in); + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/http/HttpException.java b/core/src/main/java/org/elasticsearch/http/HttpException.java index 7593afad530..69edf088401 100644 --- a/core/src/main/java/org/elasticsearch/http/HttpException.java +++ b/core/src/main/java/org/elasticsearch/http/HttpException.java @@ -20,6 +20,9 @@ package org.elasticsearch.http; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * @@ -33,4 +36,8 @@ public class HttpException extends ElasticsearchException { public HttpException(String message, Throwable cause) { super(message, cause); } + + public HttpException(StreamInput in) throws IOException { + super(in); + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/AlreadyExpiredException.java b/core/src/main/java/org/elasticsearch/index/AlreadyExpiredException.java index 9d1bff2530d..705f9a40a34 100644 --- a/core/src/main/java/org/elasticsearch/index/AlreadyExpiredException.java +++ b/core/src/main/java/org/elasticsearch/index/AlreadyExpiredException.java @@ -20,8 +20,12 @@ package org.elasticsearch.index; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.index.engine.IgnoreOnRecoveryEngineException; +import java.io.IOException; + public class AlreadyExpiredException extends ElasticsearchException implements IgnoreOnRecoveryEngineException { private String index; private String type; @@ -63,4 +67,25 @@ public class AlreadyExpiredException extends ElasticsearchException implements I public long now() { return now; } + + public AlreadyExpiredException(StreamInput in) throws IOException{ + super(in); + index = in.readOptionalString(); + type = in.readOptionalString(); + id = in.readOptionalString(); + timestamp = in.readLong(); + ttl = in.readLong(); + now = in.readLong(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeOptionalString(index); + out.writeOptionalString(type); + out.writeOptionalString(id); + out.writeLong(timestamp); + out.writeLong(ttl); + out.writeLong(now); + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/IndexException.java b/core/src/main/java/org/elasticsearch/index/IndexException.java index 2cd1edcd897..ef94c1c55d6 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexException.java +++ b/core/src/main/java/org/elasticsearch/index/IndexException.java @@ -20,6 +20,8 @@ package org.elasticsearch.index; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; @@ -56,4 +58,16 @@ public class IndexException extends ElasticsearchException { public String toString() { return "[" + (index == null ? "_na" : index.name()) + "] " + getMessage(); } + + + public IndexException(StreamInput in) throws IOException{ + super(in); + index = in.readBoolean() ? Index.readIndexName(in) : null; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeOptionalStreamable(index); + } } diff --git a/core/src/main/java/org/elasticsearch/index/IndexShardAlreadyExistsException.java b/core/src/main/java/org/elasticsearch/index/IndexShardAlreadyExistsException.java index 54f700e34e4..564988d0594 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexShardAlreadyExistsException.java +++ b/core/src/main/java/org/elasticsearch/index/IndexShardAlreadyExistsException.java @@ -20,6 +20,9 @@ package org.elasticsearch.index; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * @@ -29,4 +32,8 @@ public class IndexShardAlreadyExistsException extends ElasticsearchException { public IndexShardAlreadyExistsException(String message) { super(message); } + + public IndexShardAlreadyExistsException(StreamInput in) throws IOException { + super(in); + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/IndexShardMissingException.java b/core/src/main/java/org/elasticsearch/index/IndexShardMissingException.java index c59dcbb3384..6b356ee685f 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexShardMissingException.java +++ b/core/src/main/java/org/elasticsearch/index/IndexShardMissingException.java @@ -19,10 +19,13 @@ package org.elasticsearch.index; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ @@ -32,6 +35,10 @@ public class IndexShardMissingException extends IndexShardException { super(shardId, "missing"); } + public IndexShardMissingException(StreamInput in) throws IOException{ + super(in); + } + @Override public RestStatus status() { return RestStatus.NOT_FOUND; diff --git a/core/src/main/java/org/elasticsearch/index/engine/CloseEngineException.java b/core/src/main/java/org/elasticsearch/index/engine/CloseEngineException.java deleted file mode 100644 index f3b21f89e6d..00000000000 --- a/core/src/main/java/org/elasticsearch/index/engine/CloseEngineException.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.engine; - -import org.elasticsearch.index.shard.ShardId; - -/** - * An exception indicating that an {@link org.elasticsearch.index.engine.Engine} close failed. - * - * - */ -public class CloseEngineException extends EngineException { - - public CloseEngineException(ShardId shardId, String msg) { - super(shardId, msg); - } - - public CloseEngineException(ShardId shardId, String msg, Throwable cause) { - super(shardId, msg, cause); - } -} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/engine/CreateFailedEngineException.java b/core/src/main/java/org/elasticsearch/index/engine/CreateFailedEngineException.java index ad7ca95d4a0..1214ba9eff4 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/CreateFailedEngineException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/CreateFailedEngineException.java @@ -19,8 +19,12 @@ package org.elasticsearch.index.engine; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * */ @@ -36,6 +40,12 @@ public class CreateFailedEngineException extends EngineException { this.id = create.id(); } + public CreateFailedEngineException(StreamInput in) throws IOException{ + super(in); + type = in.readString(); + id = in.readString(); + } + public String type() { return this.type; } @@ -43,4 +53,11 @@ public class CreateFailedEngineException extends EngineException { public String id() { return this.id; } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeString(type); + out.writeString(id); + } } diff --git a/core/src/main/java/org/elasticsearch/index/engine/DeleteByQueryFailedEngineException.java b/core/src/main/java/org/elasticsearch/index/engine/DeleteByQueryFailedEngineException.java index d555cbc1a43..95d57c53836 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/DeleteByQueryFailedEngineException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/DeleteByQueryFailedEngineException.java @@ -19,8 +19,11 @@ package org.elasticsearch.index.engine; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** @deprecated Delete-by-query is removed in 2.0, but we keep this so translog can replay on upgrade. */ @Deprecated public class DeleteByQueryFailedEngineException extends EngineException { @@ -28,4 +31,8 @@ public class DeleteByQueryFailedEngineException extends EngineException { public DeleteByQueryFailedEngineException(ShardId shardId, Engine.DeleteByQuery deleteByQuery, Throwable cause) { super(shardId, "Delete by query failed for [" + deleteByQuery.query() + "]", cause); } + + public DeleteByQueryFailedEngineException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/index/engine/DeleteFailedEngineException.java b/core/src/main/java/org/elasticsearch/index/engine/DeleteFailedEngineException.java index e69351931f5..068df25e2fd 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/DeleteFailedEngineException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/DeleteFailedEngineException.java @@ -19,8 +19,11 @@ package org.elasticsearch.index.engine; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * */ @@ -29,4 +32,8 @@ public class DeleteFailedEngineException extends EngineException { public DeleteFailedEngineException(ShardId shardId, Engine.Delete delete, Throwable cause) { super(shardId, "Delete failed for [" + delete.uid().text() + "]", cause); } + + public DeleteFailedEngineException(StreamInput in) throws IOException{ + super(in); + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/engine/DocumentAlreadyExistsException.java b/core/src/main/java/org/elasticsearch/index/engine/DocumentAlreadyExistsException.java index 02bf49a649d..467dd8c14c7 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/DocumentAlreadyExistsException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/DocumentAlreadyExistsException.java @@ -18,9 +18,12 @@ */ package org.elasticsearch.index.engine; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ @@ -30,6 +33,10 @@ public class DocumentAlreadyExistsException extends EngineException { super(shardId, "[" + type + "][" + id + "]: document already exists"); } + public DocumentAlreadyExistsException(StreamInput in) throws IOException{ + super(in); + } + @Override public RestStatus status() { return RestStatus.CONFLICT; diff --git a/core/src/main/java/org/elasticsearch/index/engine/DocumentMissingException.java b/core/src/main/java/org/elasticsearch/index/engine/DocumentMissingException.java index 37350bd4334..1f6b0cd501b 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/DocumentMissingException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/DocumentMissingException.java @@ -18,9 +18,12 @@ */ package org.elasticsearch.index.engine; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ @@ -30,6 +33,10 @@ public class DocumentMissingException extends EngineException { super(shardId, "[" + type + "][" + id + "]: document missing"); } + public DocumentMissingException(StreamInput in) throws IOException{ + super(in); + } + @Override public RestStatus status() { return RestStatus.NOT_FOUND; diff --git a/core/src/main/java/org/elasticsearch/index/engine/DocumentSourceMissingException.java b/core/src/main/java/org/elasticsearch/index/engine/DocumentSourceMissingException.java index c478b10fc39..b0010162f4a 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/DocumentSourceMissingException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/DocumentSourceMissingException.java @@ -18,9 +18,12 @@ */ package org.elasticsearch.index.engine; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ @@ -30,6 +33,10 @@ public class DocumentSourceMissingException extends EngineException { super(shardId, "[" + type + "][" + id + "]: document source missing"); } + public DocumentSourceMissingException(StreamInput in) throws IOException{ + super(in); + } + @Override public RestStatus status() { return RestStatus.BAD_REQUEST; diff --git a/core/src/main/java/org/elasticsearch/index/engine/EngineAlreadyStartedException.java b/core/src/main/java/org/elasticsearch/index/engine/EngineAlreadyStartedException.java deleted file mode 100644 index fb0591c4f80..00000000000 --- a/core/src/main/java/org/elasticsearch/index/engine/EngineAlreadyStartedException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.engine; - -import org.elasticsearch.index.shard.ShardId; - -/** - * - */ -public class EngineAlreadyStartedException extends EngineException { - - public EngineAlreadyStartedException(ShardId shardId) { - super(shardId, "Already started"); - } -} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/engine/EngineClosedException.java b/core/src/main/java/org/elasticsearch/index/engine/EngineClosedException.java index f5813947ffa..ef55708622d 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/EngineClosedException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/EngineClosedException.java @@ -19,9 +19,12 @@ package org.elasticsearch.index.engine; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.IndexShardClosedException; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * An engine is already closed. *

@@ -39,4 +42,8 @@ public class EngineClosedException extends IndexShardClosedException { public EngineClosedException(ShardId shardId, Throwable t) { super(shardId, t); } + + public EngineClosedException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/index/engine/EngineCreationFailureException.java b/core/src/main/java/org/elasticsearch/index/engine/EngineCreationFailureException.java index 2036e2f47bc..14eaef3301b 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/EngineCreationFailureException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/EngineCreationFailureException.java @@ -19,8 +19,11 @@ package org.elasticsearch.index.engine; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * An exception indicating that an {@link Engine} creation failed. * @@ -32,4 +35,8 @@ public class EngineCreationFailureException extends EngineException { super(shardId, msg, cause); } + public EngineCreationFailureException(StreamInput in) throws IOException{ + super(in); + } + } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/engine/EngineException.java b/core/src/main/java/org/elasticsearch/index/engine/EngineException.java index 6b8c7e3b498..a856ed190a1 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/EngineException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/EngineException.java @@ -19,9 +19,12 @@ package org.elasticsearch.index.engine; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * */ @@ -34,4 +37,8 @@ public class EngineException extends IndexShardException { public EngineException(ShardId shardId, String msg, Throwable cause) { super(shardId, msg, cause); } + + public EngineException(StreamInput in) throws IOException{ + super(in); + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/engine/FlushFailedEngineException.java b/core/src/main/java/org/elasticsearch/index/engine/FlushFailedEngineException.java index 06cce4f9ee3..016e01c9c37 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/FlushFailedEngineException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/FlushFailedEngineException.java @@ -19,8 +19,11 @@ package org.elasticsearch.index.engine; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * */ @@ -30,7 +33,7 @@ public class FlushFailedEngineException extends EngineException { super(shardId, "Flush failed", t); } - public FlushFailedEngineException(ShardId shardId, String message, Throwable t) { - super(shardId, "Flush failed [" + message + "]", t); + public FlushFailedEngineException(StreamInput in) throws IOException{ + super(in); } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/engine/FlushNotAllowedEngineException.java b/core/src/main/java/org/elasticsearch/index/engine/FlushNotAllowedEngineException.java index 0f06520d704..d9371707e3b 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/FlushNotAllowedEngineException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/FlushNotAllowedEngineException.java @@ -19,9 +19,12 @@ package org.elasticsearch.index.engine; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ @@ -31,6 +34,10 @@ public class FlushNotAllowedEngineException extends EngineException { super(shardId, msg); } + public FlushNotAllowedEngineException(StreamInput in) throws IOException{ + super(in); + } + @Override public RestStatus status() { return RestStatus.SERVICE_UNAVAILABLE; diff --git a/core/src/main/java/org/elasticsearch/index/engine/ForceMergeFailedEngineException.java b/core/src/main/java/org/elasticsearch/index/engine/ForceMergeFailedEngineException.java index e4590f12b30..7aac909c9e8 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/ForceMergeFailedEngineException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/ForceMergeFailedEngineException.java @@ -19,8 +19,11 @@ package org.elasticsearch.index.engine; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * */ @@ -29,4 +32,8 @@ public class ForceMergeFailedEngineException extends EngineException { public ForceMergeFailedEngineException(ShardId shardId, Throwable t) { super(shardId, "force merge failed", t); } + + public ForceMergeFailedEngineException(StreamInput in) throws IOException{ + super(in); + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/engine/IndexFailedEngineException.java b/core/src/main/java/org/elasticsearch/index/engine/IndexFailedEngineException.java index 3773529ae03..09de2386976 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/IndexFailedEngineException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/IndexFailedEngineException.java @@ -19,8 +19,12 @@ package org.elasticsearch.index.engine; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * */ @@ -36,6 +40,19 @@ public class IndexFailedEngineException extends EngineException { this.id = index.id(); } + public IndexFailedEngineException(StreamInput in) throws IOException{ + super(in); + type = in.readString(); + id = in.readString(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeString(type); + out.writeString(id); + } + public String type() { return this.type; } diff --git a/core/src/main/java/org/elasticsearch/index/engine/RecoveryEngineException.java b/core/src/main/java/org/elasticsearch/index/engine/RecoveryEngineException.java index 89848499358..ee7468bdd1d 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/RecoveryEngineException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/RecoveryEngineException.java @@ -19,8 +19,12 @@ package org.elasticsearch.index.engine; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * */ @@ -33,6 +37,17 @@ public class RecoveryEngineException extends EngineException { this.phase = phase; } + public RecoveryEngineException(StreamInput in) throws IOException{ + super(in); + phase = in.readByte(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeInt(phase); + } + public int phase() { return phase; } diff --git a/core/src/main/java/org/elasticsearch/index/engine/RefreshFailedEngineException.java b/core/src/main/java/org/elasticsearch/index/engine/RefreshFailedEngineException.java index 581bef0b7a2..51e2b257518 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/RefreshFailedEngineException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/RefreshFailedEngineException.java @@ -19,8 +19,11 @@ package org.elasticsearch.index.engine; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * */ @@ -29,4 +32,8 @@ public class RefreshFailedEngineException extends EngineException { public RefreshFailedEngineException(ShardId shardId, Throwable t) { super(shardId, "Refresh failed", t); } + + public RefreshFailedEngineException(StreamInput in) throws IOException{ + super(in); + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/engine/RollbackFailedEngineException.java b/core/src/main/java/org/elasticsearch/index/engine/RollbackFailedEngineException.java deleted file mode 100644 index 0a4124ecf69..00000000000 --- a/core/src/main/java/org/elasticsearch/index/engine/RollbackFailedEngineException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.engine; - -import org.elasticsearch.index.shard.ShardId; - -/** - * - */ -public class RollbackFailedEngineException extends EngineException { - - public RollbackFailedEngineException(ShardId shardId, Throwable t) { - super(shardId, "Rollback failed", t); - } -} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/engine/RollbackNotAllowedEngineException.java b/core/src/main/java/org/elasticsearch/index/engine/RollbackNotAllowedEngineException.java deleted file mode 100644 index 3af14746dd5..00000000000 --- a/core/src/main/java/org/elasticsearch/index/engine/RollbackNotAllowedEngineException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.engine; - -import org.elasticsearch.index.shard.ShardId; - -/** - * - */ -public class RollbackNotAllowedEngineException extends EngineException { - - public RollbackNotAllowedEngineException(ShardId shardId, String msg) { - super(shardId, msg); - } -} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/engine/SnapshotFailedEngineException.java b/core/src/main/java/org/elasticsearch/index/engine/SnapshotFailedEngineException.java index 1fb18a393ea..c0296cf9db3 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/SnapshotFailedEngineException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/SnapshotFailedEngineException.java @@ -19,8 +19,11 @@ package org.elasticsearch.index.engine; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * */ @@ -30,4 +33,7 @@ public class SnapshotFailedEngineException extends EngineException { super(shardId, "Snapshot failed", cause); } + public SnapshotFailedEngineException(StreamInput in) throws IOException{ + super(in); + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/engine/VersionConflictEngineException.java b/core/src/main/java/org/elasticsearch/index/engine/VersionConflictEngineException.java index d3904f65563..8c2d35297e7 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/VersionConflictEngineException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/VersionConflictEngineException.java @@ -18,22 +18,19 @@ */ package org.elasticsearch.index.engine; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ public class VersionConflictEngineException extends EngineException { - private final long current; - - private final long provided; - public VersionConflictEngineException(ShardId shardId, String type, String id, long current, long provided) { super(shardId, "[" + type + "][" + id + "]: version conflict, current [" + current + "], provided [" + provided + "]"); - this.current = current; - this.provided = provided; } @Override @@ -41,11 +38,7 @@ public class VersionConflictEngineException extends EngineException { return RestStatus.CONFLICT; } - public long getCurrentVersion() { - return this.current; - } - - public long getProvidedVersion() { - return this.provided; + public VersionConflictEngineException(StreamInput in) throws IOException { + super(in); } } diff --git a/core/src/main/java/org/elasticsearch/index/mapper/MapperCompressionException.java b/core/src/main/java/org/elasticsearch/index/mapper/MapperCompressionException.java deleted file mode 100644 index 93034e00397..00000000000 --- a/core/src/main/java/org/elasticsearch/index/mapper/MapperCompressionException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.mapper; - -/** - * - */ -public class MapperCompressionException extends MapperException { - - public MapperCompressionException(String message) { - super(message); - } - - public MapperCompressionException(String message, Throwable cause) { - super(message, cause); - } -} \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/mapper/MapperException.java b/core/src/main/java/org/elasticsearch/index/mapper/MapperException.java index be8886d87fe..c4964a00a2b 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/MapperException.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/MapperException.java @@ -20,11 +20,17 @@ package org.elasticsearch.index.mapper; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * */ public class MapperException extends ElasticsearchException { + public MapperException(StreamInput in) throws IOException { + super(in); + } public MapperException(String message) { super(message); diff --git a/core/src/main/java/org/elasticsearch/index/mapper/MapperParsingException.java b/core/src/main/java/org/elasticsearch/index/mapper/MapperParsingException.java index 25a7e1f9233..8fb999e778a 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/MapperParsingException.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/MapperParsingException.java @@ -19,13 +19,20 @@ package org.elasticsearch.index.mapper; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ public class MapperParsingException extends MapperException { + public MapperParsingException(StreamInput in) throws IOException { + super(in); + } + public MapperParsingException(String message) { super(message); } diff --git a/core/src/main/java/org/elasticsearch/index/mapper/MergeMappingException.java b/core/src/main/java/org/elasticsearch/index/mapper/MergeMappingException.java index 387c92cad91..912d4c985b8 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/MergeMappingException.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/MergeMappingException.java @@ -19,8 +19,11 @@ package org.elasticsearch.index.mapper; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; import java.util.Arrays; /** @@ -35,6 +38,17 @@ public class MergeMappingException extends MapperException { this.failures = failures; } + public MergeMappingException(StreamInput in) throws IOException { + super(in); + failures = in.readStringArray(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeStringArray(failures); + } + public String[] failures() { return failures; } diff --git a/core/src/main/java/org/elasticsearch/index/mapper/StrictDynamicMappingException.java b/core/src/main/java/org/elasticsearch/index/mapper/StrictDynamicMappingException.java index f675396369b..f37ac8817ee 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/StrictDynamicMappingException.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/StrictDynamicMappingException.java @@ -18,8 +18,11 @@ */ package org.elasticsearch.index.mapper; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** */ public class StrictDynamicMappingException extends MapperParsingException { @@ -28,6 +31,10 @@ public class StrictDynamicMappingException extends MapperParsingException { super("mapping set to strict, dynamic introduction of [" + fieldName + "] within [" + path + "] is not allowed"); } + public StrictDynamicMappingException(StreamInput in) throws IOException { + super(in); + } + @Override public RestStatus status() { return RestStatus.BAD_REQUEST; diff --git a/core/src/main/java/org/elasticsearch/index/percolator/PercolatorException.java b/core/src/main/java/org/elasticsearch/index/percolator/PercolatorException.java index 6e0f1d1827c..65019be247b 100644 --- a/core/src/main/java/org/elasticsearch/index/percolator/PercolatorException.java +++ b/core/src/main/java/org/elasticsearch/index/percolator/PercolatorException.java @@ -18,9 +18,12 @@ */ package org.elasticsearch.index.percolator; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexException; +import java.io.IOException; + /** * Exception during indexing a percolator query. */ @@ -29,4 +32,8 @@ public class PercolatorException extends IndexException { public PercolatorException(Index index, String msg, Throwable cause) { super(index, msg, cause); } + + public PercolatorException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryParsingException.java b/core/src/main/java/org/elasticsearch/index/query/QueryParsingException.java index b9b0381e90e..b13a403f759 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryParsingException.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryParsingException.java @@ -19,6 +19,8 @@ package org.elasticsearch.index.query; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentLocation; import org.elasticsearch.common.xcontent.XContentParser; @@ -34,8 +36,8 @@ import java.io.IOException; public class QueryParsingException extends IndexException { static final int UNKNOWN_POSITION = -1; - private int lineNumber = UNKNOWN_POSITION; - private int columnNumber = UNKNOWN_POSITION; + private final int lineNumber; + private final int columnNumber; public QueryParsingException(QueryParseContext parseContext, String msg) { this(parseContext, msg, null); @@ -43,7 +45,8 @@ public class QueryParsingException extends IndexException { public QueryParsingException(QueryParseContext parseContext, String msg, Throwable cause) { super(parseContext.index(), msg, cause); - + int lineNumber = UNKNOWN_POSITION; + int columnNumber = UNKNOWN_POSITION; XContentParser parser = parseContext.parser(); if (parser != null) { XContentLocation location = parser.getTokenLocation(); @@ -52,13 +55,15 @@ public class QueryParsingException extends IndexException { columnNumber = location.columnNumber; } } + this.columnNumber = columnNumber; + this.lineNumber = lineNumber; } /** * This constructor is provided for use in unit tests where a * {@link QueryParseContext} may not be available */ - QueryParsingException(Index index, int line, int col, String msg, Throwable cause) { + public QueryParsingException(Index index, int line, int col, String msg, Throwable cause) { super(index, msg, cause); this.lineNumber = line; this.columnNumber = col; @@ -96,4 +101,17 @@ public class QueryParsingException extends IndexException { super.innerToXContent(builder, params); } + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeInt(lineNumber); + out.writeInt(columnNumber); + } + + public QueryParsingException(StreamInput in) throws IOException{ + super(in); + lineNumber = in.readInt(); + columnNumber = in.readInt(); + } + } diff --git a/core/src/main/java/org/elasticsearch/index/shard/IllegalIndexShardStateException.java b/core/src/main/java/org/elasticsearch/index/shard/IllegalIndexShardStateException.java index 3f6cf9288a9..0cde08f43c4 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IllegalIndexShardStateException.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IllegalIndexShardStateException.java @@ -19,8 +19,12 @@ package org.elasticsearch.index.shard; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ @@ -46,4 +50,15 @@ public class IllegalIndexShardStateException extends IndexShardException { public RestStatus status() { return RestStatus.NOT_FOUND; } + + public IllegalIndexShardStateException(StreamInput in) throws IOException{ + super(in); + currentState = IndexShardState.fromId(in.readByte()); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeByte(currentState.id()); + } } diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShardClosedException.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShardClosedException.java index 72fe912dd20..f4e0fb53851 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShardClosedException.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShardClosedException.java @@ -19,6 +19,10 @@ package org.elasticsearch.index.shard; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + /** * */ @@ -34,4 +38,8 @@ public class IndexShardClosedException extends IllegalIndexShardStateException { public IndexShardClosedException(ShardId shardId, String message) { super(shardId, IndexShardState.CLOSED, message); } + + public IndexShardClosedException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShardCreationException.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShardCreationException.java index 15835da2ac8..a6d879e5b01 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShardCreationException.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShardCreationException.java @@ -19,6 +19,10 @@ package org.elasticsearch.index.shard; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + /** */ public class IndexShardCreationException extends IndexShardException { @@ -26,4 +30,8 @@ public class IndexShardCreationException extends IndexShardException { public IndexShardCreationException(ShardId shardId, Throwable cause) { super(shardId, "failed to create shard", cause); } + + public IndexShardCreationException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShardException.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShardException.java index 28812b08805..23fde2abc10 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShardException.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShardException.java @@ -19,6 +19,8 @@ package org.elasticsearch.index.shard; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.IndexException; @@ -56,4 +58,19 @@ public class IndexShardException extends IndexException { } super.innerToXContent(builder, params); } + + public IndexShardException(StreamInput in) throws IOException{ + super(in); + if (in.readBoolean()) { + shardId = ShardId.readShardId(in); + } else { + shardId = null; + } + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeOptionalStreamable(shardId); + } } diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShardNotRecoveringException.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShardNotRecoveringException.java index abdd1c18188..0e05576f577 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShardNotRecoveringException.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShardNotRecoveringException.java @@ -19,6 +19,10 @@ package org.elasticsearch.index.shard; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + /** * */ @@ -27,4 +31,8 @@ public class IndexShardNotRecoveringException extends IllegalIndexShardStateExce public IndexShardNotRecoveringException(ShardId shardId, IndexShardState currentState) { super(shardId, currentState, "Shard not in recovering state"); } + + public IndexShardNotRecoveringException(StreamInput in) throws IOException{ + super(in); + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShardNotStartedException.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShardNotStartedException.java index fa9ba4be31c..ecf62bc6195 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShardNotStartedException.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShardNotStartedException.java @@ -19,6 +19,10 @@ package org.elasticsearch.index.shard; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + /** * */ @@ -27,4 +31,8 @@ public class IndexShardNotStartedException extends IllegalIndexShardStateExcepti public IndexShardNotStartedException(ShardId shardId, IndexShardState currentState) { super(shardId, currentState, "Shard not started"); } + + public IndexShardNotStartedException(StreamInput in) throws IOException{ + super(in); + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShardRecoveringException.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShardRecoveringException.java index 37a1773be22..6c27e4d93e9 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShardRecoveringException.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShardRecoveringException.java @@ -19,6 +19,10 @@ package org.elasticsearch.index.shard; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + /** * */ @@ -27,4 +31,8 @@ public class IndexShardRecoveringException extends IllegalIndexShardStateExcepti public IndexShardRecoveringException(ShardId shardId) { super(shardId, IndexShardState.RECOVERING, "Already recovering"); } + + public IndexShardRecoveringException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShardRecoveryException.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShardRecoveryException.java index 2e9ad5b29cd..d53d1eaa6a5 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShardRecoveryException.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShardRecoveryException.java @@ -19,9 +19,12 @@ package org.elasticsearch.index.shard; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * */ @@ -29,4 +32,8 @@ public class IndexShardRecoveryException extends IndexShardException { public IndexShardRecoveryException(ShardId shardId, String msg, Throwable cause) { super(shardId, msg, cause); } + + public IndexShardRecoveryException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShardRelocatedException.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShardRelocatedException.java index f678142f4d6..2d3c48cd4c5 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShardRelocatedException.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShardRelocatedException.java @@ -19,6 +19,10 @@ package org.elasticsearch.index.shard; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + /** * */ @@ -27,4 +31,8 @@ public class IndexShardRelocatedException extends IllegalIndexShardStateExceptio public IndexShardRelocatedException(ShardId shardId) { super(shardId, IndexShardState.RELOCATED, "Already relocated"); } + + public IndexShardRelocatedException(StreamInput in) throws IOException{ + super(in); + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShardStartedException.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShardStartedException.java index c909a9c97d7..05e7cdf8983 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShardStartedException.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShardStartedException.java @@ -19,6 +19,10 @@ package org.elasticsearch.index.shard; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + /** * */ @@ -27,4 +31,8 @@ public class IndexShardStartedException extends IllegalIndexShardStateException public IndexShardStartedException(ShardId shardId) { super(shardId, IndexShardState.STARTED, "Already started"); } + + public IndexShardStartedException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/index/shard/TranslogRecoveryPerformer.java b/core/src/main/java/org/elasticsearch/index/shard/TranslogRecoveryPerformer.java index 4418551bc2f..91da224ec31 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/TranslogRecoveryPerformer.java +++ b/core/src/main/java/org/elasticsearch/index/shard/TranslogRecoveryPerformer.java @@ -26,6 +26,8 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.collect.Tuple; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; @@ -39,6 +41,7 @@ import org.elasticsearch.index.query.ParsedQuery; import org.elasticsearch.index.query.QueryParsingException; import org.elasticsearch.index.translog.Translog; +import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -96,6 +99,16 @@ public class TranslogRecoveryPerformer { this.completedOperations = completedOperations; } + public BatchOperationException(StreamInput in) throws IOException{ + super(in); + completedOperations = in.readInt(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeInt(completedOperations); + } /** the number of succesful operations performed before the exception was thrown */ public int completedOperations() { diff --git a/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardRestoreException.java b/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardRestoreException.java index 705a8ef5b74..92a2ed4ab98 100644 --- a/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardRestoreException.java +++ b/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardRestoreException.java @@ -19,9 +19,12 @@ package org.elasticsearch.index.snapshots; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * Generic shard restore exception */ @@ -33,4 +36,8 @@ public class IndexShardRestoreException extends IndexShardException { public IndexShardRestoreException(ShardId shardId, String msg, Throwable cause) { super(shardId, msg, cause); } + + public IndexShardRestoreException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardRestoreFailedException.java b/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardRestoreFailedException.java index 784ba57d36d..cc774347451 100644 --- a/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardRestoreFailedException.java +++ b/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardRestoreFailedException.java @@ -19,8 +19,11 @@ package org.elasticsearch.index.snapshots; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * Thrown when restore of a shard fails */ @@ -32,4 +35,8 @@ public class IndexShardRestoreFailedException extends IndexShardRestoreException public IndexShardRestoreFailedException(ShardId shardId, String msg, Throwable cause) { super(shardId, msg, cause); } + + public IndexShardRestoreFailedException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotException.java b/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotException.java index e346654304e..e915d227538 100644 --- a/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotException.java +++ b/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotException.java @@ -19,9 +19,12 @@ package org.elasticsearch.index.snapshots; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * Generic shard snapshot exception */ @@ -33,4 +36,8 @@ public class IndexShardSnapshotException extends IndexShardException { public IndexShardSnapshotException(ShardId shardId, String msg, Throwable cause) { super(shardId, msg, cause); } + + public IndexShardSnapshotException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotFailedException.java b/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotFailedException.java index 9b9495a8bc8..bfb755c9e14 100644 --- a/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotFailedException.java +++ b/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotFailedException.java @@ -19,8 +19,11 @@ package org.elasticsearch.index.snapshots; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * Thrown when snapshot process is failed on a shard level */ @@ -32,4 +35,8 @@ public class IndexShardSnapshotFailedException extends IndexShardSnapshotExcepti public IndexShardSnapshotFailedException(ShardId shardId, String msg, Throwable cause) { super(shardId, msg, cause); } + + public IndexShardSnapshotFailedException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/index/store/StoreException.java b/core/src/main/java/org/elasticsearch/index/store/StoreException.java index c5b491eb48c..d221583e0d7 100644 --- a/core/src/main/java/org/elasticsearch/index/store/StoreException.java +++ b/core/src/main/java/org/elasticsearch/index/store/StoreException.java @@ -19,19 +19,22 @@ package org.elasticsearch.index.store; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * */ public class StoreException extends IndexShardException { - public StoreException(ShardId shardId, String msg) { - super(shardId, msg); - } - public StoreException(ShardId shardId, String msg, Throwable cause) { super(shardId, msg, cause); } + + public StoreException(StreamInput in) throws IOException{ + super(in); + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/translog/TranslogCorruptedException.java b/core/src/main/java/org/elasticsearch/index/translog/TranslogCorruptedException.java index 9196e3b0d49..07700b3037c 100644 --- a/core/src/main/java/org/elasticsearch/index/translog/TranslogCorruptedException.java +++ b/core/src/main/java/org/elasticsearch/index/translog/TranslogCorruptedException.java @@ -20,6 +20,9 @@ package org.elasticsearch.index.translog; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; public class TranslogCorruptedException extends ElasticsearchException { public TranslogCorruptedException(String msg) { @@ -29,4 +32,8 @@ public class TranslogCorruptedException extends ElasticsearchException { public TranslogCorruptedException(String msg, Throwable cause) { super(msg, cause); } + + public TranslogCorruptedException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/index/translog/TranslogException.java b/core/src/main/java/org/elasticsearch/index/translog/TranslogException.java index 8608023f6a9..2e80cb6f782 100644 --- a/core/src/main/java/org/elasticsearch/index/translog/TranslogException.java +++ b/core/src/main/java/org/elasticsearch/index/translog/TranslogException.java @@ -19,9 +19,12 @@ package org.elasticsearch.index.translog; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * */ @@ -34,4 +37,8 @@ public class TranslogException extends IndexShardException { public TranslogException(ShardId shardId, String msg, Throwable cause) { super(shardId, msg, cause); } + + public TranslogException(StreamInput in) throws IOException{ + super(in); + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/translog/TruncatedTranslogException.java b/core/src/main/java/org/elasticsearch/index/translog/TruncatedTranslogException.java index 7338b4e356a..e04eb58068d 100644 --- a/core/src/main/java/org/elasticsearch/index/translog/TruncatedTranslogException.java +++ b/core/src/main/java/org/elasticsearch/index/translog/TruncatedTranslogException.java @@ -19,9 +19,17 @@ package org.elasticsearch.index.translog; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + public class TruncatedTranslogException extends TranslogCorruptedException { public TruncatedTranslogException(String msg, Throwable cause) { super(msg, cause); } + + public TruncatedTranslogException(StreamInput in) throws IOException { + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/indices/AliasFilterParsingException.java b/core/src/main/java/org/elasticsearch/indices/AliasFilterParsingException.java index 95d1c0f4d6d..54baafe0a03 100644 --- a/core/src/main/java/org/elasticsearch/indices/AliasFilterParsingException.java +++ b/core/src/main/java/org/elasticsearch/indices/AliasFilterParsingException.java @@ -19,9 +19,12 @@ package org.elasticsearch.indices; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexException; +import java.io.IOException; + /** * */ @@ -32,4 +35,7 @@ public class AliasFilterParsingException extends IndexException { } + public AliasFilterParsingException(StreamInput in) throws IOException{ + super(in); + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/indices/IndexAlreadyExistsException.java b/core/src/main/java/org/elasticsearch/indices/IndexAlreadyExistsException.java index 4c2df2e5e92..5bd12bc3aa4 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndexAlreadyExistsException.java +++ b/core/src/main/java/org/elasticsearch/indices/IndexAlreadyExistsException.java @@ -19,10 +19,13 @@ package org.elasticsearch.indices; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexException; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ @@ -36,6 +39,10 @@ public class IndexAlreadyExistsException extends IndexException { super(index, message); } + public IndexAlreadyExistsException(StreamInput in) throws IOException{ + super(in); + } + @Override public RestStatus status() { return RestStatus.BAD_REQUEST; diff --git a/core/src/main/java/org/elasticsearch/indices/IndexClosedException.java b/core/src/main/java/org/elasticsearch/indices/IndexClosedException.java index e7080012921..d522bf2c57c 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndexClosedException.java +++ b/core/src/main/java/org/elasticsearch/indices/IndexClosedException.java @@ -19,10 +19,13 @@ package org.elasticsearch.indices; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexException; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * Exception indicating that one or more requested indices are closed. */ @@ -32,6 +35,10 @@ public class IndexClosedException extends IndexException { super(index, "closed"); } + public IndexClosedException(StreamInput in) throws IOException{ + super(in); + } + @Override public RestStatus status() { return RestStatus.FORBIDDEN; diff --git a/core/src/main/java/org/elasticsearch/indices/IndexCreationException.java b/core/src/main/java/org/elasticsearch/indices/IndexCreationException.java index 9016a45548e..e681376af09 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndexCreationException.java +++ b/core/src/main/java/org/elasticsearch/indices/IndexCreationException.java @@ -20,9 +20,12 @@ package org.elasticsearch.indices; import org.elasticsearch.ElasticsearchWrapperException; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexException; +import java.io.IOException; + /** */ public class IndexCreationException extends IndexException implements ElasticsearchWrapperException { @@ -30,4 +33,8 @@ public class IndexCreationException extends IndexException implements Elasticsea public IndexCreationException(Index index, Throwable cause) { super(index, "failed to create index", cause); } + + public IndexCreationException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/indices/IndexMissingException.java b/core/src/main/java/org/elasticsearch/indices/IndexMissingException.java index 1bec1585a7c..8b6d7735c93 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndexMissingException.java +++ b/core/src/main/java/org/elasticsearch/indices/IndexMissingException.java @@ -19,10 +19,13 @@ package org.elasticsearch.indices; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexException; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ @@ -32,6 +35,10 @@ public class IndexMissingException extends IndexException { super(index, "no such index"); } + public IndexMissingException(StreamInput in) throws IOException{ + super(in); + } + @Override public RestStatus status() { return RestStatus.NOT_FOUND; diff --git a/core/src/main/java/org/elasticsearch/indices/IndexPrimaryShardNotAllocatedException.java b/core/src/main/java/org/elasticsearch/indices/IndexPrimaryShardNotAllocatedException.java index 1c1caed81f6..0dda08fe7ff 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndexPrimaryShardNotAllocatedException.java +++ b/core/src/main/java/org/elasticsearch/indices/IndexPrimaryShardNotAllocatedException.java @@ -19,15 +19,21 @@ package org.elasticsearch.indices; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexException; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * Thrown when some action cannot be performed because the primary shard of * some shard group in an index has not been allocated post api action. */ public class IndexPrimaryShardNotAllocatedException extends IndexException { + public IndexPrimaryShardNotAllocatedException(StreamInput in) throws IOException{ + super(in); + } public IndexPrimaryShardNotAllocatedException(Index index) { super(index, "primary not allocated post api"); diff --git a/core/src/main/java/org/elasticsearch/indices/IndexTemplateAlreadyExistsException.java b/core/src/main/java/org/elasticsearch/indices/IndexTemplateAlreadyExistsException.java index 5775de0200b..3b665e051e0 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndexTemplateAlreadyExistsException.java +++ b/core/src/main/java/org/elasticsearch/indices/IndexTemplateAlreadyExistsException.java @@ -19,8 +19,12 @@ package org.elasticsearch.indices; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ @@ -33,6 +37,11 @@ public class IndexTemplateAlreadyExistsException extends ElasticsearchException this.name = name; } + public IndexTemplateAlreadyExistsException(StreamInput in) throws IOException { + super(in); + name = in.readOptionalString(); + } + public String name() { return this.name; } @@ -41,4 +50,10 @@ public class IndexTemplateAlreadyExistsException extends ElasticsearchException public RestStatus status() { return RestStatus.BAD_REQUEST; } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeOptionalString(name); + } } diff --git a/core/src/main/java/org/elasticsearch/indices/IndexTemplateMissingException.java b/core/src/main/java/org/elasticsearch/indices/IndexTemplateMissingException.java index ba1948ef5a2..db3b232d0e3 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndexTemplateMissingException.java +++ b/core/src/main/java/org/elasticsearch/indices/IndexTemplateMissingException.java @@ -19,8 +19,12 @@ package org.elasticsearch.indices; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ @@ -33,10 +37,20 @@ public class IndexTemplateMissingException extends ElasticsearchException { this.name = name; } + public IndexTemplateMissingException(StreamInput in) throws IOException { + super(in); + name = in.readOptionalString(); + } + public String name() { return this.name; } + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeOptionalString(name); + } @Override public RestStatus status() { diff --git a/core/src/main/java/org/elasticsearch/indices/InvalidAliasNameException.java b/core/src/main/java/org/elasticsearch/indices/InvalidAliasNameException.java index 9dee3f700b4..179f6ca8517 100644 --- a/core/src/main/java/org/elasticsearch/indices/InvalidAliasNameException.java +++ b/core/src/main/java/org/elasticsearch/indices/InvalidAliasNameException.java @@ -19,10 +19,13 @@ package org.elasticsearch.indices; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexException; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ @@ -32,6 +35,10 @@ public class InvalidAliasNameException extends IndexException { super(index, "Invalid alias name [" + name + "], " + desc); } + public InvalidAliasNameException(StreamInput in) throws IOException{ + super(in); + } + @Override public RestStatus status() { return RestStatus.BAD_REQUEST; diff --git a/core/src/main/java/org/elasticsearch/indices/InvalidIndexNameException.java b/core/src/main/java/org/elasticsearch/indices/InvalidIndexNameException.java index 3f16a3b5841..468d158f389 100644 --- a/core/src/main/java/org/elasticsearch/indices/InvalidIndexNameException.java +++ b/core/src/main/java/org/elasticsearch/indices/InvalidIndexNameException.java @@ -19,10 +19,13 @@ package org.elasticsearch.indices; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexException; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ @@ -32,6 +35,10 @@ public class InvalidIndexNameException extends IndexException { super(index, "Invalid index name [" + name + "], " + desc); } + public InvalidIndexNameException(StreamInput in) throws IOException{ + super(in); + } + @Override public RestStatus status() { diff --git a/core/src/main/java/org/elasticsearch/indices/InvalidIndexTemplateException.java b/core/src/main/java/org/elasticsearch/indices/InvalidIndexTemplateException.java index d9ad8c5fcc6..e3ed97415ef 100644 --- a/core/src/main/java/org/elasticsearch/indices/InvalidIndexTemplateException.java +++ b/core/src/main/java/org/elasticsearch/indices/InvalidIndexTemplateException.java @@ -19,8 +19,12 @@ package org.elasticsearch.indices; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ @@ -41,4 +45,15 @@ public class InvalidIndexTemplateException extends ElasticsearchException { public RestStatus status() { return RestStatus.BAD_REQUEST; } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeOptionalString(name); + } + + public InvalidIndexTemplateException(StreamInput in) throws IOException{ + super(in); + name = in.readOptionalString(); + } } diff --git a/core/src/main/java/org/elasticsearch/indices/InvalidTypeNameException.java b/core/src/main/java/org/elasticsearch/indices/InvalidTypeNameException.java index 106e76f0926..2279860d80c 100644 --- a/core/src/main/java/org/elasticsearch/indices/InvalidTypeNameException.java +++ b/core/src/main/java/org/elasticsearch/indices/InvalidTypeNameException.java @@ -19,14 +19,21 @@ package org.elasticsearch.indices; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.mapper.MapperException; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ public class InvalidTypeNameException extends MapperException { + public InvalidTypeNameException(StreamInput in) throws IOException { + super(in); + } + public InvalidTypeNameException(String message) { super(message); } diff --git a/core/src/main/java/org/elasticsearch/indices/TypeMissingException.java b/core/src/main/java/org/elasticsearch/indices/TypeMissingException.java index eb80c057a45..ef4a1d6d8d5 100644 --- a/core/src/main/java/org/elasticsearch/indices/TypeMissingException.java +++ b/core/src/main/java/org/elasticsearch/indices/TypeMissingException.java @@ -19,10 +19,12 @@ package org.elasticsearch.indices; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexException; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; import java.util.Arrays; /** @@ -34,6 +36,10 @@ public class TypeMissingException extends IndexException { super(index, "type[" + Arrays.toString(types) + "] missing"); } + public TypeMissingException(StreamInput in) throws IOException{ + super(in); + } + @Override public RestStatus status() { return RestStatus.NOT_FOUND; diff --git a/core/src/main/java/org/elasticsearch/indices/recovery/DelayRecoveryException.java b/core/src/main/java/org/elasticsearch/indices/recovery/DelayRecoveryException.java index f9c47d0e2ea..7edae6a76b5 100644 --- a/core/src/main/java/org/elasticsearch/indices/recovery/DelayRecoveryException.java +++ b/core/src/main/java/org/elasticsearch/indices/recovery/DelayRecoveryException.java @@ -20,6 +20,9 @@ package org.elasticsearch.indices.recovery; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * An exception marking that this recovery attempt should be ignored (since probably, we already recovered). @@ -32,7 +35,8 @@ public class DelayRecoveryException extends ElasticsearchException { super(msg); } - public DelayRecoveryException(String msg, Throwable cause) { - super(msg, cause); + public DelayRecoveryException(StreamInput in) throws IOException{ + super(in); } + } diff --git a/core/src/main/java/org/elasticsearch/indices/recovery/IgnoreRecoveryException.java b/core/src/main/java/org/elasticsearch/indices/recovery/IgnoreRecoveryException.java deleted file mode 100644 index 2ea2ca5780b..00000000000 --- a/core/src/main/java/org/elasticsearch/indices/recovery/IgnoreRecoveryException.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.indices.recovery; - -import org.elasticsearch.ElasticsearchException; - -/** - * An exception marking that this recovery attempt should be ignored (since probably, we already recovered). - * - * - */ -public class IgnoreRecoveryException extends ElasticsearchException { - - public IgnoreRecoveryException(String msg) { - super(msg); - } - - public IgnoreRecoveryException(String msg, Throwable cause) { - super(msg, cause); - } -} diff --git a/core/src/main/java/org/elasticsearch/indices/recovery/RecoverFilesRecoveryException.java b/core/src/main/java/org/elasticsearch/indices/recovery/RecoverFilesRecoveryException.java index 143920897d7..dea6e08e9cf 100644 --- a/core/src/main/java/org/elasticsearch/indices/recovery/RecoverFilesRecoveryException.java +++ b/core/src/main/java/org/elasticsearch/indices/recovery/RecoverFilesRecoveryException.java @@ -20,10 +20,14 @@ package org.elasticsearch.indices.recovery; import org.elasticsearch.ElasticsearchWrapperException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * */ @@ -46,4 +50,17 @@ public class RecoverFilesRecoveryException extends IndexShardException implement public ByteSizeValue totalFilesSize() { return totalFilesSize; } + + public RecoverFilesRecoveryException(StreamInput in) throws IOException{ + super(in); + numberOfFiles = in.readInt(); + totalFilesSize = ByteSizeValue.readBytesSizeValue(in); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeInt(numberOfFiles); + totalFilesSize.writeTo(out); + } } diff --git a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryFailedException.java b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryFailedException.java index 53f1ae878a5..3c3d96a4f9b 100644 --- a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryFailedException.java +++ b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryFailedException.java @@ -22,8 +22,11 @@ package org.elasticsearch.indices.recovery; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * */ @@ -48,4 +51,8 @@ public class RecoveryFailedException extends ElasticsearchException { public RecoveryFailedException(ShardId shardId, DiscoveryNode sourceNode, DiscoveryNode targetNode, @Nullable String extraInfo, Throwable cause) { super(shardId + ": Recovery failed from " + sourceNode + " into " + targetNode + (extraInfo == null ? "" : " (" + extraInfo + ")"), cause); } + + public RecoveryFailedException(StreamInput in) throws IOException { + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/node/NodeClosedException.java b/core/src/main/java/org/elasticsearch/node/NodeClosedException.java index 280efd57dd3..6f6b4ebf14a 100644 --- a/core/src/main/java/org/elasticsearch/node/NodeClosedException.java +++ b/core/src/main/java/org/elasticsearch/node/NodeClosedException.java @@ -21,6 +21,9 @@ package org.elasticsearch.node; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * An exception indicating that node is closed. @@ -32,4 +35,8 @@ public class NodeClosedException extends ElasticsearchException { public NodeClosedException(DiscoveryNode node) { super("node closed " + node); } + + public NodeClosedException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/percolator/PercolateException.java b/core/src/main/java/org/elasticsearch/percolator/PercolateException.java index c5b7fa7d677..6b9b035ca12 100644 --- a/core/src/main/java/org/elasticsearch/percolator/PercolateException.java +++ b/core/src/main/java/org/elasticsearch/percolator/PercolateException.java @@ -21,8 +21,12 @@ package org.elasticsearch.percolator; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchWrapperException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * Exception during percolating document(s) at runtime. */ @@ -30,11 +34,6 @@ public class PercolateException extends ElasticsearchException implements Elasti private final ShardId shardId; - public PercolateException(String msg, ShardId shardId) { - super(msg); - this.shardId = shardId; - } - public PercolateException(ShardId shardId, String msg, Throwable cause) { super(msg, cause); this.shardId = shardId; @@ -43,4 +42,15 @@ public class PercolateException extends ElasticsearchException implements Elasti public ShardId getShardId() { return shardId; } + + public PercolateException(StreamInput in) throws IOException{ + super(in); + shardId = ShardId.readShardId(in); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + shardId.writeTo(out); + } } diff --git a/core/src/main/java/org/elasticsearch/repositories/RepositoryException.java b/core/src/main/java/org/elasticsearch/repositories/RepositoryException.java index f2593ce0d1f..c916d9fbac6 100644 --- a/core/src/main/java/org/elasticsearch/repositories/RepositoryException.java +++ b/core/src/main/java/org/elasticsearch/repositories/RepositoryException.java @@ -20,6 +20,10 @@ package org.elasticsearch.repositories; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; /** * Generic repository exception @@ -44,4 +48,15 @@ public class RepositoryException extends ElasticsearchException { public String repository() { return repository; } + + public RepositoryException(StreamInput in) throws IOException{ + super(in); + repository = in.readOptionalString(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeOptionalString(repository); + } } diff --git a/core/src/main/java/org/elasticsearch/repositories/RepositoryMissingException.java b/core/src/main/java/org/elasticsearch/repositories/RepositoryMissingException.java index 11d56bafc0e..fe513619d06 100644 --- a/core/src/main/java/org/elasticsearch/repositories/RepositoryMissingException.java +++ b/core/src/main/java/org/elasticsearch/repositories/RepositoryMissingException.java @@ -19,8 +19,12 @@ package org.elasticsearch.repositories; +import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * Repository missing exception */ @@ -35,4 +39,8 @@ public class RepositoryMissingException extends RepositoryException { public RestStatus status() { return RestStatus.NOT_FOUND; } + + public RepositoryMissingException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/repositories/RepositoryVerificationException.java b/core/src/main/java/org/elasticsearch/repositories/RepositoryVerificationException.java index 8e70e4b6a36..3f8429f1f15 100644 --- a/core/src/main/java/org/elasticsearch/repositories/RepositoryVerificationException.java +++ b/core/src/main/java/org/elasticsearch/repositories/RepositoryVerificationException.java @@ -19,8 +19,12 @@ package org.elasticsearch.repositories; +import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * Repository verification exception */ @@ -39,5 +43,9 @@ public class RepositoryVerificationException extends RepositoryException { public RestStatus status() { return RestStatus.INTERNAL_SERVER_ERROR; } + + public RepositoryVerificationException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/rest/HasRestHeaders.java b/core/src/main/java/org/elasticsearch/rest/HasRestHeaders.java index e76a7bed68d..2eaeb89dee0 100644 --- a/core/src/main/java/org/elasticsearch/rest/HasRestHeaders.java +++ b/core/src/main/java/org/elasticsearch/rest/HasRestHeaders.java @@ -19,6 +19,8 @@ package org.elasticsearch.rest; +import org.elasticsearch.ElasticsearchException; + import java.util.List; import java.util.Map; @@ -27,7 +29,7 @@ import java.util.Map; * get translated to a rest response, can implement this interface and the headers will be added * the the response. * - * @see org.elasticsearch.ElasticsearchException.WithRestHeaders + * @see ElasticsearchException.WithRestHeadersException */ public interface HasRestHeaders { diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesMissingException.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesMissingException.java index dfc98b0cb82..daf6679d754 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesMissingException.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesMissingException.java @@ -19,8 +19,11 @@ package org.elasticsearch.rest.action.admin.indices.alias.delete; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; import java.util.Arrays; /** @@ -43,4 +46,15 @@ public class AliasesMissingException extends ElasticsearchException { public RestStatus status() { return RestStatus.NOT_FOUND; } + + public AliasesMissingException(StreamInput in) throws IOException{ + super(in); + names = in.readStringArray(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeStringArray(names); + } } diff --git a/core/src/main/java/org/elasticsearch/script/Script.java b/core/src/main/java/org/elasticsearch/script/Script.java index 1139e3cc9e6..9e637cf0a1d 100644 --- a/core/src/main/java/org/elasticsearch/script/Script.java +++ b/core/src/main/java/org/elasticsearch/script/Script.java @@ -293,8 +293,8 @@ public class Script implements ToXContent, Streamable { super(LoggerMessageFormat.format(msg, args)); } - public ScriptParseException(String msg, Throwable cause, Object... args) { - super(LoggerMessageFormat.format(msg, args), cause); + public ScriptParseException(StreamInput in) throws IOException{ + super(in); } } } diff --git a/core/src/main/java/org/elasticsearch/script/ScriptException.java b/core/src/main/java/org/elasticsearch/script/ScriptException.java index 4b031d23aa7..3cc3560da7c 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptException.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptException.java @@ -20,6 +20,9 @@ package org.elasticsearch.script; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * @@ -33,4 +36,8 @@ public class ScriptException extends ElasticsearchException { public ScriptException(String msg, Throwable cause) { super(msg, cause); } + + public ScriptException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/script/expression/ExpressionScriptCompilationException.java b/core/src/main/java/org/elasticsearch/script/expression/ExpressionScriptCompilationException.java index e02401efc15..f7e901001e4 100644 --- a/core/src/main/java/org/elasticsearch/script/expression/ExpressionScriptCompilationException.java +++ b/core/src/main/java/org/elasticsearch/script/expression/ExpressionScriptCompilationException.java @@ -20,7 +20,9 @@ package org.elasticsearch.script.expression; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; +import java.io.IOException; import java.text.ParseException; /** @@ -33,4 +35,8 @@ public class ExpressionScriptCompilationException extends ElasticsearchException public ExpressionScriptCompilationException(String msg) { super(msg); } + + public ExpressionScriptCompilationException(StreamInput in) throws IOException { + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/script/expression/ExpressionScriptExecutionException.java b/core/src/main/java/org/elasticsearch/script/expression/ExpressionScriptExecutionException.java index 66ff30b9e13..435b12207ec 100644 --- a/core/src/main/java/org/elasticsearch/script/expression/ExpressionScriptExecutionException.java +++ b/core/src/main/java/org/elasticsearch/script/expression/ExpressionScriptExecutionException.java @@ -20,6 +20,9 @@ package org.elasticsearch.script.expression; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * Exception used to wrap exceptions occuring while running expressions. @@ -28,6 +31,11 @@ public class ExpressionScriptExecutionException extends ElasticsearchException { public ExpressionScriptExecutionException(String msg, Throwable cause) { super(msg, cause); } + + public ExpressionScriptExecutionException(StreamInput in) throws IOException { + super(in); + } + public ExpressionScriptExecutionException(String msg) { super(msg); } diff --git a/core/src/main/java/org/elasticsearch/script/groovy/GroovyScriptCompilationException.java b/core/src/main/java/org/elasticsearch/script/groovy/GroovyScriptCompilationException.java index ea86eb9b347..d7c52ee6721 100644 --- a/core/src/main/java/org/elasticsearch/script/groovy/GroovyScriptCompilationException.java +++ b/core/src/main/java/org/elasticsearch/script/groovy/GroovyScriptCompilationException.java @@ -20,8 +20,11 @@ package org.elasticsearch.script.groovy; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * Exception used to wrap groovy script compilation exceptions so they are * correctly serialized between nodes. @@ -31,6 +34,10 @@ public class GroovyScriptCompilationException extends ElasticsearchException { super(message); } + public GroovyScriptCompilationException(StreamInput in) throws IOException{ + super(in); + } + @Override public RestStatus status() { return RestStatus.BAD_REQUEST; diff --git a/core/src/main/java/org/elasticsearch/script/groovy/GroovyScriptExecutionException.java b/core/src/main/java/org/elasticsearch/script/groovy/GroovyScriptExecutionException.java index cb19b488deb..0293c251425 100644 --- a/core/src/main/java/org/elasticsearch/script/groovy/GroovyScriptExecutionException.java +++ b/core/src/main/java/org/elasticsearch/script/groovy/GroovyScriptExecutionException.java @@ -20,8 +20,11 @@ package org.elasticsearch.script.groovy; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * Exception used to wrap groovy script execution exceptions so they are * correctly serialized between nodes. @@ -30,12 +33,13 @@ public class GroovyScriptExecutionException extends ElasticsearchException { public GroovyScriptExecutionException(String message) { super(message); } - public GroovyScriptExecutionException(String message, Throwable t) { - super(message, t); - } @Override public RestStatus status() { return RestStatus.BAD_REQUEST; } + + public GroovyScriptExecutionException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/search/SearchContextException.java b/core/src/main/java/org/elasticsearch/search/SearchContextException.java index 599515830e1..4fa1750d321 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchContextException.java +++ b/core/src/main/java/org/elasticsearch/search/SearchContextException.java @@ -19,8 +19,11 @@ package org.elasticsearch.search; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.search.internal.SearchContext; +import java.io.IOException; + /** * */ @@ -34,6 +37,10 @@ public class SearchContextException extends SearchException { super(context.shardTarget(), buildMessage(context, msg), t); } + public SearchContextException(StreamInput in) throws IOException { + super(in); + } + private static String buildMessage(SearchContext context, String msg) { return msg; } diff --git a/core/src/main/java/org/elasticsearch/search/SearchContextMissingException.java b/core/src/main/java/org/elasticsearch/search/SearchContextMissingException.java index 044cddfde30..d2f30e72c3a 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchContextMissingException.java +++ b/core/src/main/java/org/elasticsearch/search/SearchContextMissingException.java @@ -20,8 +20,12 @@ package org.elasticsearch.search; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * */ @@ -42,4 +46,15 @@ public class SearchContextMissingException extends ElasticsearchException { public RestStatus status() { return RestStatus.NOT_FOUND; } + + public SearchContextMissingException(StreamInput in) throws IOException{ + super(in); + id = in.readLong(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeLong(id); + } } diff --git a/core/src/main/java/org/elasticsearch/search/SearchException.java b/core/src/main/java/org/elasticsearch/search/SearchException.java index bc3579b7e2e..ac41fe9caed 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchException.java +++ b/core/src/main/java/org/elasticsearch/search/SearchException.java @@ -20,6 +20,10 @@ package org.elasticsearch.search; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; /** * @@ -38,6 +42,21 @@ public class SearchException extends ElasticsearchException { this.shardTarget = shardTarget; } + public SearchException(StreamInput in) throws IOException { + super(in); + if (in.readBoolean()) { + shardTarget = SearchShardTarget.readSearchShardTarget(in); + } else { + shardTarget = null; + } + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeOptionalStreamable(shardTarget); + } + public SearchShardTarget shard() { return this.shardTarget; } diff --git a/core/src/main/java/org/elasticsearch/search/SearchParseException.java b/core/src/main/java/org/elasticsearch/search/SearchParseException.java index 15c6bfd6f90..49f8a9c7cf0 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchParseException.java +++ b/core/src/main/java/org/elasticsearch/search/SearchParseException.java @@ -20,8 +20,11 @@ package org.elasticsearch.search; import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentLocation; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.search.internal.SearchContext; @@ -33,8 +36,8 @@ import java.io.IOException; public class SearchParseException extends SearchContextException { public static final int UNKNOWN_POSITION = -1; - private int lineNumber = UNKNOWN_POSITION; - private int columnNumber = UNKNOWN_POSITION; + private final int lineNumber; + private final int columnNumber; public SearchParseException(SearchContext context, String msg, @Nullable XContentLocation location) { this(context, msg, location, null); @@ -42,10 +45,29 @@ public class SearchParseException extends SearchContextException { public SearchParseException(SearchContext context, String msg, @Nullable XContentLocation location, Throwable cause) { super(context, msg, cause); + int lineNumber = UNKNOWN_POSITION; + int columnNumber = UNKNOWN_POSITION; if (location != null) { - lineNumber = location.lineNumber; - columnNumber = location.columnNumber; + if (location != null) { + lineNumber = location.lineNumber; + columnNumber = location.columnNumber; + } } + this.columnNumber = columnNumber; + this.lineNumber = lineNumber; + } + + public SearchParseException(StreamInput in) throws IOException { + super(in); + lineNumber = in.readInt(); + columnNumber = in.readInt(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeInt(lineNumber); + out.writeInt(columnNumber); } @Override diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/AggregationExecutionException.java b/core/src/main/java/org/elasticsearch/search/aggregations/AggregationExecutionException.java index 60afa4e98b3..88d41a3036b 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/AggregationExecutionException.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/AggregationExecutionException.java @@ -19,6 +19,9 @@ package org.elasticsearch.search.aggregations; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * Thrown when failing to execute an aggregation @@ -32,4 +35,8 @@ public class AggregationExecutionException extends ElasticsearchException { public AggregationExecutionException(String msg, Throwable cause) { super(msg, cause); } + + public AggregationExecutionException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/AggregationInitializationException.java b/core/src/main/java/org/elasticsearch/search/aggregations/AggregationInitializationException.java index b7f859529d6..6550ba40dd5 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/AggregationInitializationException.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/AggregationInitializationException.java @@ -19,6 +19,9 @@ package org.elasticsearch.search.aggregations; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * Thrown when failing to execute an aggregation @@ -32,4 +35,8 @@ public class AggregationInitializationException extends ElasticsearchException { public AggregationInitializationException(String msg, Throwable cause) { super(msg, cause); } + + public AggregationInitializationException(StreamInput in) throws IOException{ + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/InvalidAggregationPathException.java b/core/src/main/java/org/elasticsearch/search/aggregations/InvalidAggregationPathException.java index e2ab1f65245..60c7e1ae9a7 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/InvalidAggregationPathException.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/InvalidAggregationPathException.java @@ -20,6 +20,9 @@ package org.elasticsearch.search.aggregations; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; public class InvalidAggregationPathException extends ElasticsearchException { @@ -30,4 +33,8 @@ public class InvalidAggregationPathException extends ElasticsearchException { public InvalidAggregationPathException(String msg, Throwable cause) { super(msg, cause); } + + public InvalidAggregationPathException(StreamInput in) throws IOException { + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilderException.java b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilderException.java index d0ecd55dde1..1c764e28346 100644 --- a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilderException.java +++ b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilderException.java @@ -20,6 +20,9 @@ package org.elasticsearch.search.builder; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * @@ -33,4 +36,8 @@ public class SearchSourceBuilderException extends ElasticsearchException { public SearchSourceBuilderException(String msg, Throwable cause) { super(msg, cause); } + + public SearchSourceBuilderException(StreamInput in) throws IOException { + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/search/dfs/DfsPhaseExecutionException.java b/core/src/main/java/org/elasticsearch/search/dfs/DfsPhaseExecutionException.java index 2490c8bd1a0..a6020b4498a 100644 --- a/core/src/main/java/org/elasticsearch/search/dfs/DfsPhaseExecutionException.java +++ b/core/src/main/java/org/elasticsearch/search/dfs/DfsPhaseExecutionException.java @@ -19,9 +19,12 @@ package org.elasticsearch.search.dfs; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.search.SearchContextException; import org.elasticsearch.search.internal.SearchContext; +import java.io.IOException; + /** * */ @@ -30,4 +33,8 @@ public class DfsPhaseExecutionException extends SearchContextException { public DfsPhaseExecutionException(SearchContext context, String msg, Throwable t) { super(context, "Dfs Failed [" + msg + "]", t); } + + public DfsPhaseExecutionException(StreamInput in) throws IOException { + super(in); + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/fetch/FetchPhaseExecutionException.java b/core/src/main/java/org/elasticsearch/search/fetch/FetchPhaseExecutionException.java index ae275553c5d..1f56ac87142 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/FetchPhaseExecutionException.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/FetchPhaseExecutionException.java @@ -19,19 +19,22 @@ package org.elasticsearch.search.fetch; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.search.SearchContextException; import org.elasticsearch.search.internal.SearchContext; +import java.io.IOException; + /** * */ public class FetchPhaseExecutionException extends SearchContextException { - public FetchPhaseExecutionException(SearchContext context, String msg) { - super(context, "Fetch Failed [" + msg + "]"); - } - public FetchPhaseExecutionException(SearchContext context, String msg, Throwable t) { super(context, "Fetch Failed [" + msg + "]", t); } + + public FetchPhaseExecutionException(StreamInput in) throws IOException { + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/search/query/QueryPhaseExecutionException.java b/core/src/main/java/org/elasticsearch/search/query/QueryPhaseExecutionException.java index 6d968fce6bb..c90f1247e77 100644 --- a/core/src/main/java/org/elasticsearch/search/query/QueryPhaseExecutionException.java +++ b/core/src/main/java/org/elasticsearch/search/query/QueryPhaseExecutionException.java @@ -19,9 +19,12 @@ package org.elasticsearch.search.query; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.search.SearchContextException; import org.elasticsearch.search.internal.SearchContext; +import java.io.IOException; + /** * */ @@ -31,6 +34,10 @@ public class QueryPhaseExecutionException extends SearchContextException { super(context, "Query Failed [" + msg + "]", cause); } + public QueryPhaseExecutionException(StreamInput in) throws IOException { + super(in); + } + public QueryPhaseExecutionException(SearchContext context, String msg) { super(context, msg); } diff --git a/core/src/main/java/org/elasticsearch/search/suggest/SuggestBuilderException.java b/core/src/main/java/org/elasticsearch/search/suggest/SuggestBuilderException.java deleted file mode 100644 index e3cd7278080..00000000000 --- a/core/src/main/java/org/elasticsearch/search/suggest/SuggestBuilderException.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.search.suggest; - -import org.elasticsearch.ElasticsearchException; - -/** - * Exception thrown when errors are encountered in building Suggest lookup queries - * via {@link org.elasticsearch.search.suggest.SuggestBuilder} - */ -public class SuggestBuilderException extends ElasticsearchException { - - public SuggestBuilderException(String msg) { - super(msg); - } - - public SuggestBuilderException(String msg, Throwable cause) { - super(msg, cause); - } -} diff --git a/core/src/main/java/org/elasticsearch/search/warmer/IndexWarmerMissingException.java b/core/src/main/java/org/elasticsearch/search/warmer/IndexWarmerMissingException.java index 3892714bb0d..98459ea7c5c 100644 --- a/core/src/main/java/org/elasticsearch/search/warmer/IndexWarmerMissingException.java +++ b/core/src/main/java/org/elasticsearch/search/warmer/IndexWarmerMissingException.java @@ -19,8 +19,11 @@ package org.elasticsearch.search.warmer; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; import java.util.Arrays; /** @@ -40,8 +43,19 @@ public class IndexWarmerMissingException extends ElasticsearchException { } + public IndexWarmerMissingException(StreamInput in) throws IOException{ + super(in); + names = in.readStringArray(); + } + @Override public RestStatus status() { return RestStatus.NOT_FOUND; } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeStringArray(names); + } } diff --git a/core/src/main/java/org/elasticsearch/snapshots/ConcurrentSnapshotExecutionException.java b/core/src/main/java/org/elasticsearch/snapshots/ConcurrentSnapshotExecutionException.java index 6214ca5f6da..4a844fb4907 100644 --- a/core/src/main/java/org/elasticsearch/snapshots/ConcurrentSnapshotExecutionException.java +++ b/core/src/main/java/org/elasticsearch/snapshots/ConcurrentSnapshotExecutionException.java @@ -20,8 +20,11 @@ package org.elasticsearch.snapshots; import org.elasticsearch.cluster.metadata.SnapshotId; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * Thrown when a user tries to start multiple snapshots at the same time */ @@ -30,8 +33,8 @@ public class ConcurrentSnapshotExecutionException extends SnapshotException { super(snapshot, msg); } - public ConcurrentSnapshotExecutionException(SnapshotId snapshot, String msg, Throwable cause) { - super(snapshot, msg, cause); + public ConcurrentSnapshotExecutionException(StreamInput in) throws IOException { + super(in); } @Override diff --git a/core/src/main/java/org/elasticsearch/snapshots/InvalidSnapshotNameException.java b/core/src/main/java/org/elasticsearch/snapshots/InvalidSnapshotNameException.java index ee7e47b0a27..48949c11d4c 100644 --- a/core/src/main/java/org/elasticsearch/snapshots/InvalidSnapshotNameException.java +++ b/core/src/main/java/org/elasticsearch/snapshots/InvalidSnapshotNameException.java @@ -20,8 +20,11 @@ package org.elasticsearch.snapshots; import org.elasticsearch.cluster.metadata.SnapshotId; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * Thrown on the attempt to create a snapshot with invalid name */ @@ -31,6 +34,10 @@ public class InvalidSnapshotNameException extends SnapshotException { super(snapshot, "Invalid snapshot name [" + snapshot.getSnapshot() + "], " + desc); } + public InvalidSnapshotNameException(StreamInput in) throws IOException { + super(in); + } + @Override public RestStatus status() { return RestStatus.BAD_REQUEST; diff --git a/core/src/main/java/org/elasticsearch/snapshots/SnapshotCreationException.java b/core/src/main/java/org/elasticsearch/snapshots/SnapshotCreationException.java index 3b78337cb23..3c8cdc4d067 100644 --- a/core/src/main/java/org/elasticsearch/snapshots/SnapshotCreationException.java +++ b/core/src/main/java/org/elasticsearch/snapshots/SnapshotCreationException.java @@ -21,14 +21,17 @@ package org.elasticsearch.snapshots; import org.elasticsearch.ElasticsearchWrapperException; import org.elasticsearch.cluster.metadata.SnapshotId; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * Thrown when snapshot creation fails completely */ public class SnapshotCreationException extends SnapshotException { - public SnapshotCreationException(SnapshotId snapshot, String message) { - super(snapshot, message); + public SnapshotCreationException(StreamInput in) throws IOException { + super(in); } public SnapshotCreationException(SnapshotId snapshot, Throwable cause) { diff --git a/core/src/main/java/org/elasticsearch/snapshots/SnapshotException.java b/core/src/main/java/org/elasticsearch/snapshots/SnapshotException.java index 7a47d90a295..b109c46f46b 100644 --- a/core/src/main/java/org/elasticsearch/snapshots/SnapshotException.java +++ b/core/src/main/java/org/elasticsearch/snapshots/SnapshotException.java @@ -21,6 +21,10 @@ package org.elasticsearch.snapshots; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.cluster.metadata.SnapshotId; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; /** * Generic snapshot exception @@ -37,6 +41,21 @@ public class SnapshotException extends ElasticsearchException { this.snapshot = snapshot; } + public SnapshotException(StreamInput in) throws IOException { + super(in); + if (in.readBoolean()) { + snapshot = SnapshotId.readSnapshotId(in); + } else { + snapshot = null; + } + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeOptionalStreamable(snapshot); + } + public SnapshotId snapshot() { return snapshot; } diff --git a/core/src/main/java/org/elasticsearch/snapshots/SnapshotMissingException.java b/core/src/main/java/org/elasticsearch/snapshots/SnapshotMissingException.java index 1a8ead00f35..150729f2cbf 100644 --- a/core/src/main/java/org/elasticsearch/snapshots/SnapshotMissingException.java +++ b/core/src/main/java/org/elasticsearch/snapshots/SnapshotMissingException.java @@ -20,22 +20,24 @@ package org.elasticsearch.snapshots; import org.elasticsearch.cluster.metadata.SnapshotId; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.rest.RestStatus; +import java.io.IOException; + /** * Thrown if requested snapshot doesn't exist */ public class SnapshotMissingException extends SnapshotException { - - public SnapshotMissingException(SnapshotId snapshot) { - super(snapshot, "is missing"); - } - public SnapshotMissingException(SnapshotId snapshot, Throwable cause) { super(snapshot, "is missing", cause); } + public SnapshotMissingException(StreamInput in) throws IOException { + super(in); + } + @Override public RestStatus status() { return RestStatus.NOT_FOUND; diff --git a/core/src/main/java/org/elasticsearch/snapshots/SnapshotRestoreException.java b/core/src/main/java/org/elasticsearch/snapshots/SnapshotRestoreException.java index 0b9280eaf9c..940f8162e6b 100644 --- a/core/src/main/java/org/elasticsearch/snapshots/SnapshotRestoreException.java +++ b/core/src/main/java/org/elasticsearch/snapshots/SnapshotRestoreException.java @@ -20,6 +20,9 @@ package org.elasticsearch.snapshots; import org.elasticsearch.cluster.metadata.SnapshotId; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * Snapshot restore exception @@ -32,4 +35,8 @@ public class SnapshotRestoreException extends SnapshotException { public SnapshotRestoreException(SnapshotId snapshot, String message, Throwable cause) { super(snapshot, message, cause); } + + public SnapshotRestoreException(StreamInput in) throws IOException { + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/transport/ActionNotFoundTransportException.java b/core/src/main/java/org/elasticsearch/transport/ActionNotFoundTransportException.java index b53af40663a..61d322f2606 100644 --- a/core/src/main/java/org/elasticsearch/transport/ActionNotFoundTransportException.java +++ b/core/src/main/java/org/elasticsearch/transport/ActionNotFoundTransportException.java @@ -19,6 +19,11 @@ package org.elasticsearch.transport; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; + /** * An exception indicating that a transport action was not found. * @@ -28,11 +33,22 @@ public class ActionNotFoundTransportException extends TransportException { private final String action; + public ActionNotFoundTransportException(StreamInput in) throws IOException { + super(in); + action = in.readOptionalString(); + } + public ActionNotFoundTransportException(String action) { super("No handler for action [" + action + "]"); this.action = action; } + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeOptionalString(action); + } + public String action() { return this.action; } diff --git a/core/src/main/java/org/elasticsearch/transport/ActionTransportException.java b/core/src/main/java/org/elasticsearch/transport/ActionTransportException.java index bc430a4f671..9b0e887c219 100644 --- a/core/src/main/java/org/elasticsearch/transport/ActionTransportException.java +++ b/core/src/main/java/org/elasticsearch/transport/ActionTransportException.java @@ -19,7 +19,12 @@ package org.elasticsearch.transport; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.transport.TransportAddress; +import org.elasticsearch.common.transport.TransportAddressSerializers; + +import java.io.IOException; /** * An action invocation failure. @@ -28,12 +33,18 @@ import org.elasticsearch.common.transport.TransportAddress; */ public class ActionTransportException extends TransportException { - private TransportAddress address; + private final TransportAddress address; - private String action; + private final String action; - public ActionTransportException(String msg, Throwable cause) { - super(msg, cause); + public ActionTransportException(StreamInput in) throws IOException { + super(in); + if (in.readBoolean()) { + address = TransportAddressSerializers.addressFromStream(in); + } else { + address = null; + } + action = in.readOptionalString(); } public ActionTransportException(String name, TransportAddress address, String action, Throwable cause) { @@ -48,6 +59,18 @@ public class ActionTransportException extends TransportException { this.action = action; } + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + if (address != null) { + out.writeBoolean(true); + TransportAddressSerializers.addressToStream(out, address); + } else { + out.writeBoolean(false); + } + out.writeOptionalString(action); + } + /** * The target address to invoke the action on. */ diff --git a/core/src/main/java/org/elasticsearch/transport/BindTransportException.java b/core/src/main/java/org/elasticsearch/transport/BindTransportException.java index 41738ec919d..66591c7e501 100644 --- a/core/src/main/java/org/elasticsearch/transport/BindTransportException.java +++ b/core/src/main/java/org/elasticsearch/transport/BindTransportException.java @@ -19,13 +19,17 @@ package org.elasticsearch.transport; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + /** * */ public class BindTransportException extends TransportException { - public BindTransportException(String message) { - super(message); + public BindTransportException(StreamInput in) throws IOException { + super(in); } public BindTransportException(String message, Throwable cause) { diff --git a/core/src/main/java/org/elasticsearch/transport/ConnectTransportException.java b/core/src/main/java/org/elasticsearch/transport/ConnectTransportException.java index 1a5517d5fd1..4e6e3a8cb62 100644 --- a/core/src/main/java/org/elasticsearch/transport/ConnectTransportException.java +++ b/core/src/main/java/org/elasticsearch/transport/ConnectTransportException.java @@ -20,6 +20,10 @@ package org.elasticsearch.transport; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; /** * @@ -45,6 +49,21 @@ public class ConnectTransportException extends ActionTransportException { this.node = node; } + public ConnectTransportException(StreamInput in) throws IOException { + super(in); + if (in.readBoolean()) { + node = DiscoveryNode.readNode(in); + } else { + node = null; + } + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeOptionalStreamable(node); + } + public DiscoveryNode node() { return node; } diff --git a/core/src/main/java/org/elasticsearch/transport/FailedCommunicationException.java b/core/src/main/java/org/elasticsearch/transport/FailedCommunicationException.java deleted file mode 100644 index ccb6d81b011..00000000000 --- a/core/src/main/java/org/elasticsearch/transport/FailedCommunicationException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.transport; - -/** - * - */ -public class FailedCommunicationException extends TransportException { - - public FailedCommunicationException(String message) { - super(message); - } - - public FailedCommunicationException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/core/src/main/java/org/elasticsearch/transport/NodeDisconnectedException.java b/core/src/main/java/org/elasticsearch/transport/NodeDisconnectedException.java index ed94aa443ee..a5abd21082d 100644 --- a/core/src/main/java/org/elasticsearch/transport/NodeDisconnectedException.java +++ b/core/src/main/java/org/elasticsearch/transport/NodeDisconnectedException.java @@ -20,6 +20,9 @@ package org.elasticsearch.transport; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * @@ -30,6 +33,10 @@ public class NodeDisconnectedException extends ConnectTransportException { super(node, "disconnected", action, null); } + public NodeDisconnectedException(StreamInput in) throws IOException { + super(in); + } + // stack trace is meaningless... @Override diff --git a/core/src/main/java/org/elasticsearch/transport/NodeNotConnectedException.java b/core/src/main/java/org/elasticsearch/transport/NodeNotConnectedException.java index 78133834c91..98691b6a0f4 100644 --- a/core/src/main/java/org/elasticsearch/transport/NodeNotConnectedException.java +++ b/core/src/main/java/org/elasticsearch/transport/NodeNotConnectedException.java @@ -20,6 +20,9 @@ package org.elasticsearch.transport; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * An exception indicating that a message is sent to a node that is not connected. @@ -29,10 +32,10 @@ import org.elasticsearch.cluster.node.DiscoveryNode; public class NodeNotConnectedException extends ConnectTransportException { public NodeNotConnectedException(DiscoveryNode node, String msg) { - super(node, msg); + super(node, msg, (String)null); } - public NodeNotConnectedException(DiscoveryNode node, String msg, Throwable cause) { - super(node, msg, cause); + public NodeNotConnectedException(StreamInput in) throws IOException { + super(in); } } diff --git a/core/src/main/java/org/elasticsearch/transport/NodeShouldNotConnectException.java b/core/src/main/java/org/elasticsearch/transport/NodeShouldNotConnectException.java index 5792e588363..9ea621bc40d 100644 --- a/core/src/main/java/org/elasticsearch/transport/NodeShouldNotConnectException.java +++ b/core/src/main/java/org/elasticsearch/transport/NodeShouldNotConnectException.java @@ -20,6 +20,9 @@ package org.elasticsearch.transport; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** */ @@ -28,4 +31,8 @@ public class NodeShouldNotConnectException extends NodeNotConnectedException { public NodeShouldNotConnectException(DiscoveryNode fromNode, DiscoveryNode node) { super(node, "node should not connect from [" + fromNode + "]"); } + + public NodeShouldNotConnectException(StreamInput in) throws IOException { + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/transport/NotSerializableTransportException.java b/core/src/main/java/org/elasticsearch/transport/NotSerializableTransportException.java index 9f753122abd..9a838628aeb 100644 --- a/core/src/main/java/org/elasticsearch/transport/NotSerializableTransportException.java +++ b/core/src/main/java/org/elasticsearch/transport/NotSerializableTransportException.java @@ -19,6 +19,10 @@ package org.elasticsearch.transport; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + /** * */ @@ -28,6 +32,10 @@ public class NotSerializableTransportException extends TransportException { super(buildMessage(t)); } + public NotSerializableTransportException(StreamInput in) throws IOException { + super(in); + } + @Override public Throwable fillInStackTrace() { return null; diff --git a/core/src/main/java/org/elasticsearch/transport/ReceiveTimeoutTransportException.java b/core/src/main/java/org/elasticsearch/transport/ReceiveTimeoutTransportException.java index a790fc0337c..e16357f9621 100644 --- a/core/src/main/java/org/elasticsearch/transport/ReceiveTimeoutTransportException.java +++ b/core/src/main/java/org/elasticsearch/transport/ReceiveTimeoutTransportException.java @@ -20,6 +20,9 @@ package org.elasticsearch.transport; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * @@ -30,6 +33,10 @@ public class ReceiveTimeoutTransportException extends ActionTransportException { super(node.name(), node.address(), action, msg, null); } + public ReceiveTimeoutTransportException(StreamInput in) throws IOException { + super(in); + } + // @Override public Throwable fillInStackTrace() { // return fillStack(); // } diff --git a/core/src/main/java/org/elasticsearch/transport/RemoteTransportException.java b/core/src/main/java/org/elasticsearch/transport/RemoteTransportException.java index eaca6481193..5d8ffdc2609 100644 --- a/core/src/main/java/org/elasticsearch/transport/RemoteTransportException.java +++ b/core/src/main/java/org/elasticsearch/transport/RemoteTransportException.java @@ -20,8 +20,11 @@ package org.elasticsearch.transport; import org.elasticsearch.ElasticsearchWrapperException; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.transport.TransportAddress; +import java.io.IOException; + /** * A remote exception for an action. A wrapper exception around the actual remote cause and does not fill the * stack trace. @@ -31,13 +34,17 @@ import org.elasticsearch.common.transport.TransportAddress; public class RemoteTransportException extends ActionTransportException implements ElasticsearchWrapperException { public RemoteTransportException(String msg, Throwable cause) { - super(msg, cause); + super(msg, null, null, cause); } public RemoteTransportException(String name, TransportAddress address, String action, Throwable cause) { super(name, address, action, cause); } + public RemoteTransportException(StreamInput in) throws IOException { + super(in); + } + @Override public Throwable fillInStackTrace() { // no need for stack trace here, we always have cause diff --git a/core/src/main/java/org/elasticsearch/transport/ResponseHandlerFailureTransportException.java b/core/src/main/java/org/elasticsearch/transport/ResponseHandlerFailureTransportException.java index 4ba707a3e1f..a79e57441fe 100644 --- a/core/src/main/java/org/elasticsearch/transport/ResponseHandlerFailureTransportException.java +++ b/core/src/main/java/org/elasticsearch/transport/ResponseHandlerFailureTransportException.java @@ -19,6 +19,10 @@ package org.elasticsearch.transport; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + /** * A failure to handle the response of a transaction action. * @@ -30,8 +34,12 @@ public class ResponseHandlerFailureTransportException extends TransportException super(cause.getMessage(), cause); } + public ResponseHandlerFailureTransportException(StreamInput in) throws IOException { + super(in); + } + @Override public Throwable fillInStackTrace() { return null; - } + } // why is this? } diff --git a/core/src/main/java/org/elasticsearch/transport/ResponseHandlerNotFoundTransportException.java b/core/src/main/java/org/elasticsearch/transport/ResponseHandlerNotFoundTransportException.java deleted file mode 100644 index 381ce51942d..00000000000 --- a/core/src/main/java/org/elasticsearch/transport/ResponseHandlerNotFoundTransportException.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.transport; - -/** - * - */ -public class ResponseHandlerNotFoundTransportException extends TransportException { - - private final long requestId; - - public ResponseHandlerNotFoundTransportException(long requestId) { - super("Transport response handler not found of id [" + requestId + "]"); - this.requestId = requestId; - } - - public long requestId() { - return requestId; - } -} diff --git a/core/src/main/java/org/elasticsearch/transport/SendRequestTransportException.java b/core/src/main/java/org/elasticsearch/transport/SendRequestTransportException.java index a62d9807565..7c4faa5e87b 100644 --- a/core/src/main/java/org/elasticsearch/transport/SendRequestTransportException.java +++ b/core/src/main/java/org/elasticsearch/transport/SendRequestTransportException.java @@ -21,6 +21,9 @@ package org.elasticsearch.transport; import org.elasticsearch.ElasticsearchWrapperException; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * @@ -30,4 +33,8 @@ public class SendRequestTransportException extends ActionTransportException impl public SendRequestTransportException(DiscoveryNode node, String action, Throwable cause) { super(node == null ? null : node.name(), node == null ? null : node.address(), action, cause); } + + public SendRequestTransportException(StreamInput in) throws IOException { + super(in); + } } diff --git a/core/src/main/java/org/elasticsearch/transport/TransportException.java b/core/src/main/java/org/elasticsearch/transport/TransportException.java index 66a22c5d01a..a672fb939e5 100644 --- a/core/src/main/java/org/elasticsearch/transport/TransportException.java +++ b/core/src/main/java/org/elasticsearch/transport/TransportException.java @@ -20,11 +20,17 @@ package org.elasticsearch.transport; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * */ public class TransportException extends ElasticsearchException { + public TransportException(StreamInput in) throws IOException { + super(in); + } public TransportException(String msg) { super(msg); diff --git a/core/src/main/java/org/elasticsearch/transport/TransportSerializationException.java b/core/src/main/java/org/elasticsearch/transport/TransportSerializationException.java index ee92fe6fa45..ad42af9b048 100644 --- a/core/src/main/java/org/elasticsearch/transport/TransportSerializationException.java +++ b/core/src/main/java/org/elasticsearch/transport/TransportSerializationException.java @@ -19,13 +19,17 @@ package org.elasticsearch.transport; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + /** * */ public class TransportSerializationException extends TransportException { - public TransportSerializationException(String msg) { - super(msg); + public TransportSerializationException(StreamInput in) throws IOException { + super(in); } public TransportSerializationException(String msg, Throwable cause) { diff --git a/core/src/main/java/org/elasticsearch/transport/local/LocalTransport.java b/core/src/main/java/org/elasticsearch/transport/local/LocalTransport.java index fec8ffef812..cc7a8fd81a8 100644 --- a/core/src/main/java/org/elasticsearch/transport/local/LocalTransport.java +++ b/core/src/main/java/org/elasticsearch/transport/local/LocalTransport.java @@ -26,7 +26,6 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.component.Lifecycle; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.io.ThrowableObjectInputStream; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.settings.Settings; @@ -337,8 +336,7 @@ public class LocalTransport extends AbstractLifecycleComponent implem private void handlerResponseError(StreamInput buffer, final TransportResponseHandler handler) { Throwable error; try { - ThrowableObjectInputStream ois = new ThrowableObjectInputStream(buffer, settings.getClassLoader()); - error = (Throwable) ois.readObject(); + error = buffer.readThrowable(); } catch (Throwable e) { error = new TransportSerializationException("Failed to deserialize exception response from stream", e); } @@ -347,7 +345,7 @@ public class LocalTransport extends AbstractLifecycleComponent implem private void handleException(final TransportResponseHandler handler, Throwable error) { if (!(error instanceof RemoteTransportException)) { - error = new RemoteTransportException("None remote transport exception", error); + error = new RemoteTransportException("None remote transport exception", null, null, error); } final RemoteTransportException rtx = (RemoteTransportException) error; try { diff --git a/core/src/main/java/org/elasticsearch/transport/local/LocalTransportChannel.java b/core/src/main/java/org/elasticsearch/transport/local/LocalTransportChannel.java index 5a4d83e9e11..dd753e6beb7 100644 --- a/core/src/main/java/org/elasticsearch/transport/local/LocalTransportChannel.java +++ b/core/src/main/java/org/elasticsearch/transport/local/LocalTransportChannel.java @@ -20,13 +20,11 @@ package org.elasticsearch.transport.local; import org.elasticsearch.Version; -import org.elasticsearch.common.io.ThrowableObjectOutputStream; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.transport.*; import org.elasticsearch.transport.support.TransportStatus; import java.io.IOException; -import java.io.NotSerializableException; /** * @@ -90,20 +88,10 @@ public class LocalTransportChannel implements TransportChannel { @Override public void sendResponse(Throwable error) throws IOException { BytesStreamOutput stream = new BytesStreamOutput(); - try { - writeResponseExceptionHeader(stream); - RemoteTransportException tx = new RemoteTransportException(targetTransport.nodeName(), targetTransport.boundAddress().boundAddress(), action, error); - ThrowableObjectOutputStream too = new ThrowableObjectOutputStream(stream); - too.writeObject(tx); - too.close(); - } catch (NotSerializableException e) { - stream.reset(); - writeResponseExceptionHeader(stream); - RemoteTransportException tx = new RemoteTransportException(targetTransport.nodeName(), targetTransport.boundAddress().boundAddress(), action, new NotSerializableTransportException(error)); - ThrowableObjectOutputStream too = new ThrowableObjectOutputStream(stream); - too.writeObject(tx); - too.close(); - } + writeResponseExceptionHeader(stream); + RemoteTransportException tx = new RemoteTransportException(targetTransport.nodeName(), targetTransport.boundAddress().boundAddress(), action, error); + stream.writeThrowable(tx); + final byte[] data = stream.bytes().toBytes(); targetTransport.workers().execute(new Runnable() { @Override diff --git a/core/src/main/java/org/elasticsearch/transport/netty/MessageChannelHandler.java b/core/src/main/java/org/elasticsearch/transport/netty/MessageChannelHandler.java index 540e5f730d3..b713398e20f 100644 --- a/core/src/main/java/org/elasticsearch/transport/netty/MessageChannelHandler.java +++ b/core/src/main/java/org/elasticsearch/transport/netty/MessageChannelHandler.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.component.Lifecycle; import org.elasticsearch.common.compress.Compressor; import org.elasticsearch.common.compress.CompressorFactory; import org.elasticsearch.common.compress.NotCompressedException; -import org.elasticsearch.common.io.ThrowableObjectInputStream; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.transport.InetSocketTransportAddress; @@ -202,8 +201,7 @@ public class MessageChannelHandler extends SimpleChannelUpstreamHandler { private void handlerResponseError(StreamInput buffer, final TransportResponseHandler handler) { Throwable error; try { - ThrowableObjectInputStream ois = new ThrowableObjectInputStream(buffer, transport.settings().getClassLoader()); - error = (Throwable) ois.readObject(); + error = buffer.readThrowable(); } catch (Throwable e) { error = new TransportSerializationException("Failed to deserialize exception response from stream", e); } diff --git a/core/src/main/java/org/elasticsearch/transport/netty/NettyTransportChannel.java b/core/src/main/java/org/elasticsearch/transport/netty/NettyTransportChannel.java index 8edc8024b9f..e601d8016d2 100644 --- a/core/src/main/java/org/elasticsearch/transport/netty/NettyTransportChannel.java +++ b/core/src/main/java/org/elasticsearch/transport/netty/NettyTransportChannel.java @@ -23,7 +23,6 @@ import org.elasticsearch.Version; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.ReleasablePagedBytesReference; import org.elasticsearch.common.compress.CompressorFactory; -import org.elasticsearch.common.io.ThrowableObjectOutputStream; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -116,21 +115,9 @@ public class NettyTransportChannel implements TransportChannel { @Override public void sendResponse(Throwable error) throws IOException { BytesStreamOutput stream = new BytesStreamOutput(); - try { - stream.skip(NettyHeader.HEADER_SIZE); - RemoteTransportException tx = new RemoteTransportException(transport.nodeName(), transport.wrapAddress(channel.getLocalAddress()), action, error); - ThrowableObjectOutputStream too = new ThrowableObjectOutputStream(stream); - too.writeObject(tx); - too.close(); - } catch (NotSerializableException e) { - stream.reset(); - stream.skip(NettyHeader.HEADER_SIZE); - RemoteTransportException tx = new RemoteTransportException(transport.nodeName(), transport.wrapAddress(channel.getLocalAddress()), action, new NotSerializableTransportException(error)); - ThrowableObjectOutputStream too = new ThrowableObjectOutputStream(stream); - too.writeObject(tx); - too.close(); - } - + stream.skip(NettyHeader.HEADER_SIZE); + RemoteTransportException tx = new RemoteTransportException(transport.nodeName(), transport.wrapAddress(channel.getLocalAddress()), action, error); + stream.writeThrowable(tx); byte status = 0; status = TransportStatus.setResponse(status); status = TransportStatus.setError(status); diff --git a/core/src/main/java/org/elasticsearch/transport/netty/SizeHeaderFrameDecoder.java b/core/src/main/java/org/elasticsearch/transport/netty/SizeHeaderFrameDecoder.java index 8d2c3b5fe9e..f38dc1dc02d 100644 --- a/core/src/main/java/org/elasticsearch/transport/netty/SizeHeaderFrameDecoder.java +++ b/core/src/main/java/org/elasticsearch/transport/netty/SizeHeaderFrameDecoder.java @@ -19,8 +19,8 @@ package org.elasticsearch.transport.netty; -import com.google.common.base.Charsets; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.monitor.jvm.JvmInfo; import org.elasticsearch.rest.RestStatus; @@ -30,6 +30,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.handler.codec.frame.FrameDecoder; import org.jboss.netty.handler.codec.frame.TooLongFrameException; +import java.io.IOException; import java.io.StreamCorruptedException; /** @@ -105,7 +106,7 @@ public class SizeHeaderFrameDecoder extends FrameDecoder { * A helper exception to mark an incoming connection as potentially being HTTP * so an appropriate error code can be returned */ - public class HttpOnTransportException extends ElasticsearchException { + public static class HttpOnTransportException extends ElasticsearchException { public HttpOnTransportException(String msg) { super(msg); @@ -115,5 +116,9 @@ public class SizeHeaderFrameDecoder extends FrameDecoder { public RestStatus status() { return RestStatus.BAD_REQUEST; } + + public HttpOnTransportException(StreamInput in) throws IOException{ + super(in); + } } } \ No newline at end of file diff --git a/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java b/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java index b00c76ded6f..5a30cb05b04 100644 --- a/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java +++ b/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java @@ -19,6 +19,9 @@ package org.elasticsearch; +import org.apache.lucene.index.CorruptIndexException; +import org.apache.lucene.index.IndexFormatTooNewException; +import org.apache.lucene.index.IndexFormatTooOldException; import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.elasticsearch.action.search.ShardSearchFailure; import org.elasticsearch.common.io.stream.BytesStreamOutput; @@ -222,7 +225,7 @@ public class ElasticsearchExceptionTests extends ElasticsearchTestCase { public void testSerializeElasticsearchException() throws IOException { BytesStreamOutput out = new BytesStreamOutput(); - QueryParsingException ex = new TestQueryParsingException(new Index("foo"), 1, 2, "foobar", null); + QueryParsingException ex = new QueryParsingException(new Index("foo"), 1, 2, "foobar", null); out.writeThrowable(ex); StreamInput in = StreamInput.wrap(out.bytes()); @@ -233,4 +236,55 @@ public class ElasticsearchExceptionTests extends ElasticsearchTestCase { assertEquals(ex.getColumnNumber(), e.getColumnNumber()); } + public void testSerializeUnknownException() throws IOException { + BytesStreamOutput out = new BytesStreamOutput(); + QueryParsingException queryParsingException = new QueryParsingException(new Index("foo"), 1, 2, "foobar", null); + Throwable ex = new Throwable("wtf", queryParsingException); + out.writeThrowable(ex); + + StreamInput in = StreamInput.wrap(out.bytes()); + Throwable throwable = in.readThrowable(); + assertEquals("wtf", throwable.getMessage()); + assertTrue(throwable instanceof ElasticsearchException); + QueryParsingException e = (QueryParsingException)throwable.getCause(); + assertEquals(queryParsingException.index(), e.index()); + assertEquals(queryParsingException.getMessage(), e.getMessage()); + assertEquals(queryParsingException.getLineNumber(), e.getLineNumber()); + assertEquals(queryParsingException.getColumnNumber(), e.getColumnNumber()); + } + + public void testWriteThrowable() throws IOException { + Throwable[] causes = new Throwable[] { + new IllegalStateException("foobar"), + new IllegalArgumentException("alalaal"), + new NullPointerException("boom"), + new EOFException("dadada"), + new SecurityException("nono!"), + new NumberFormatException("not a number"), + new CorruptIndexException("baaaam", "this is my resource"), + new IndexFormatTooNewException("tooo new", 1, 1, 1), + new IndexFormatTooOldException("tooo new", 1, 1, 1), + new Throwable("this exception is unknown", new QueryParsingException(new Index("foo"), 1, 2, "foobar", null) ), // somethin unknown + }; + for (Throwable t : causes) { + BytesStreamOutput out = new BytesStreamOutput(); + ElasticsearchException ex = new ElasticsearchException("topLevel", t); + out.writeThrowable(ex); + StreamInput in = StreamInput.wrap(out.bytes()); + ElasticsearchException e = in.readThrowable(); + assertEquals(e.getMessage(), ex.getMessage()); + if (t instanceof IndexFormatTooNewException || t instanceof IndexFormatTooOldException) { + // these don't work yet - missing ctors + assertNotEquals(e.getCause().getMessage(), ex.getCause().getMessage()); + } else { + assertEquals(e.getCause().getMessage(), ex.getCause().getMessage()); + } + assertEquals(e.getCause().getClass(), e.getCause().getClass()); + assertArrayEquals(e.getStackTrace(), ex.getStackTrace()); + assertTrue(e.getStackTrace().length > 1); + } + + + } + } \ No newline at end of file diff --git a/core/src/test/java/org/elasticsearch/ExceptionRegistrationTests.java b/core/src/test/java/org/elasticsearch/ExceptionRegistrationTests.java new file mode 100644 index 00000000000..3493b57776d --- /dev/null +++ b/core/src/test/java/org/elasticsearch/ExceptionRegistrationTests.java @@ -0,0 +1,127 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch; + +import com.google.common.collect.Sets; +import org.elasticsearch.common.io.PathUtils; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.test.ElasticsearchTestCase; + +import java.io.IOException; +import java.lang.reflect.Modifier; +import java.net.URISyntaxException; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.HashSet; +import java.util.Set; + +public class ExceptionRegistrationTests extends ElasticsearchTestCase { + + public void testExceptionRegistration() + throws ClassNotFoundException, IOException, URISyntaxException { + final Set notRegistered = new HashSet<>(); + final Set registered = new HashSet<>(); + final String path = "/org/elasticsearch"; + final Path startPath = PathUtils.get(ElasticsearchException.class.getProtectionDomain().getCodeSource().getLocation().toURI()).resolve("org").resolve("elasticsearch"); + final Set ignore = Sets.newHashSet( + org.elasticsearch.test.rest.parser.RestTestParseException.class, + org.elasticsearch.index.query.TestQueryParsingException.class, + org.elasticsearch.test.rest.client.RestException.class, + org.elasticsearch.common.util.CancellableThreadsTest.CustomException.class, + org.elasticsearch.rest.BytesRestResponseTests.WithHeadersException.class, + org.elasticsearch.client.AbstractClientHeadersTests.InternalException.class); + FileVisitor visitor = new FileVisitor() { + private Path pkgPrefix = PathUtils.get(path).getParent(); + + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + Path next = pkgPrefix.resolve(dir.getFileName()); + if (ignore.contains(next)) { + return FileVisitResult.SKIP_SUBTREE; + } + pkgPrefix = next; + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + try { + String filename = file.getFileName().toString(); + if (filename.endsWith(".class")) { + Class clazz = loadClass(filename); + if (ignore.contains(clazz) == false) { + if (Modifier.isAbstract(clazz.getModifiers()) == false && Modifier.isInterface(clazz.getModifiers()) == false && isEsException(clazz)) { + if (ElasticsearchException.MAPPING.containsKey(clazz.getName()) == false && ElasticsearchException.class.equals(clazz.getEnclosingClass()) == false) { + notRegistered.add(clazz); + } else if (ElasticsearchException.MAPPING.containsKey(clazz.getName())) { + registered.add(clazz.getName()); + } + } + } + + } + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + return FileVisitResult.CONTINUE; + } + + private boolean isEsException(Class clazz) { + return ElasticsearchException.class.isAssignableFrom(clazz); + } + + private Class loadClass(String filename) throws ClassNotFoundException { + StringBuilder pkg = new StringBuilder(); + for (Path p : pkgPrefix) { + pkg.append(p.getFileName().toString()).append("."); + } + pkg.append(filename.substring(0, filename.length() - 6)); + return Thread.currentThread().getContextClassLoader().loadClass(pkg.toString()); + } + + @Override + public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { + throw exc; + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + pkgPrefix = pkgPrefix.getParent(); + return FileVisitResult.CONTINUE; + } + }; + Files.walkFileTree(startPath, visitor); + final Path testStartPath = PathUtils.get(ExceptionRegistrationTests.class.getResource(path).toURI()); + Files.walkFileTree(testStartPath, visitor); + assertTrue(notRegistered.remove(TestException.class)); + assertTrue("Classes subclassing ElasticsearchException must be registered \n" + notRegistered.toString(), + notRegistered.isEmpty()); + assertTrue(registered.removeAll(ElasticsearchException.MAPPING.keySet())); // check + assertEquals(registered.toString(), 0 ,registered.size()); + } + + public static final class TestException extends ElasticsearchException { + public TestException(StreamInput in) throws IOException{ + super(in); + } + } +} diff --git a/core/src/test/java/org/elasticsearch/client/AbstractClientHeadersTests.java b/core/src/test/java/org/elasticsearch/client/AbstractClientHeadersTests.java index c75e0e62489..b68ba8441ee 100644 --- a/core/src/test/java/org/elasticsearch/client/AbstractClientHeadersTests.java +++ b/core/src/test/java/org/elasticsearch/client/AbstractClientHeadersTests.java @@ -174,7 +174,7 @@ public abstract class AbstractClientHeadersTests extends ElasticsearchTestCase { } } - protected static class InternalException extends Exception { + public static class InternalException extends Exception { private final String action; private final Map headers; diff --git a/core/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeTests.java b/core/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeTests.java deleted file mode 100644 index ff20115b20e..00000000000 --- a/core/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeTests.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.cluster.node; - -import org.elasticsearch.Version; -import org.elasticsearch.common.io.ThrowableObjectInputStream; -import org.elasticsearch.common.io.ThrowableObjectOutputStream; -import org.elasticsearch.common.io.stream.BytesStreamOutput; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.transport.LocalTransportAddress; -import org.elasticsearch.common.transport.TransportAddress; -import org.elasticsearch.test.ElasticsearchTestCase; -import org.hamcrest.Matchers; -import org.junit.Test; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import static org.elasticsearch.test.VersionUtils.randomVersion; - -public class DiscoveryNodeTests extends ElasticsearchTestCase { - - - @Test - public void testJavaSerializablilty() throws IOException, ClassNotFoundException { - final int iters = scaledRandomIntBetween(100, 300); - for (int i = 0; i < iters; i++) { - final String id = randomUnicodeOfLengthBetween(3, 20); - final String nodeName = randomUnicodeOfLengthBetween(3, 20); - final String hostName = randomUnicodeOfLengthBetween(3, 20); - final String hostAddress = randomUnicodeOfLengthBetween(3, 20); - final TransportAddress transportAddress = new LocalTransportAddress(randomUnicodeOfLengthBetween(3, 20)); - final Map attributes = new HashMap<>(); - for (int a = randomInt(10); a > 0; a--) { - attributes.put(randomUnicodeOfLengthBetween(3, 20), randomUnicodeOfLengthBetween(3, 20)); - } - final Version version = randomVersion(random()); - DiscoveryNode discoveryNode = new DiscoveryNode(nodeName, id, hostName, hostAddress, transportAddress, attributes, version); - BytesStreamOutput bytesOutput = new BytesStreamOutput(); - ThrowableObjectOutputStream too = new ThrowableObjectOutputStream(bytesOutput); - too.writeObject(discoveryNode); - too.close(); - ThrowableObjectInputStream from = new ThrowableObjectInputStream(StreamInput.wrap(bytesOutput.bytes())); - DiscoveryNode readDiscoveryNode = (DiscoveryNode) from.readObject(); - from.close(); - assertThat(readDiscoveryNode, Matchers.equalTo(discoveryNode)); - assertThat(readDiscoveryNode.id(), Matchers.equalTo(id)); - assertThat(readDiscoveryNode.name(), Matchers.equalTo(nodeName)); - assertThat(readDiscoveryNode.getHostName(), Matchers.equalTo(hostName)); - assertThat(readDiscoveryNode.getHostAddress(), Matchers.equalTo(hostAddress)); - assertThat(readDiscoveryNode.address(), Matchers.equalTo(transportAddress)); - assertThat(readDiscoveryNode.attributes(), Matchers.equalTo(attributes)); - assertThat(readDiscoveryNode.version(), Matchers.equalTo(version)); - } - } - -} diff --git a/core/src/test/java/org/elasticsearch/common/util/CancellableThreadsTest.java b/core/src/test/java/org/elasticsearch/common/util/CancellableThreadsTest.java index 66db5241b7e..d2cacb9c49e 100644 --- a/core/src/test/java/org/elasticsearch/common/util/CancellableThreadsTest.java +++ b/core/src/test/java/org/elasticsearch/common/util/CancellableThreadsTest.java @@ -27,7 +27,7 @@ import java.util.concurrent.CountDownLatch; public class CancellableThreadsTest extends ElasticsearchTestCase { - private static class CustomException extends RuntimeException { + public static class CustomException extends RuntimeException { public CustomException(String msg) { super(msg); diff --git a/core/src/test/java/org/elasticsearch/rest/BytesRestResponseTests.java b/core/src/test/java/org/elasticsearch/rest/BytesRestResponseTests.java index 579408366e9..f60b178c400 100644 --- a/core/src/test/java/org/elasticsearch/rest/BytesRestResponseTests.java +++ b/core/src/test/java/org/elasticsearch/rest/BytesRestResponseTests.java @@ -48,7 +48,7 @@ public class BytesRestResponseTests extends ElasticsearchTestCase { RestRequest request = new FakeRestRequest(); RestChannel channel = randomBoolean() ? new DetailedExceptionRestChannel(request) : new SimpleExceptionRestChannel(request); - BytesRestResponse response = new BytesRestResponse(channel, new ExceptionWithHeaders()); + BytesRestResponse response = new BytesRestResponse(channel, new WithHeadersException()); assertThat(response.getHeaders().get("n1"), notNullValue()); assertThat(response.getHeaders().get("n1"), contains("v11", "v12")); assertThat(response.getHeaders().get("n2"), notNullValue()); @@ -152,9 +152,9 @@ public class BytesRestResponseTests extends ElasticsearchTestCase { assertEquals(expected.trim(), text.trim()); } - private static class ExceptionWithHeaders extends ElasticsearchException.WithRestHeaders { + public static class WithHeadersException extends ElasticsearchException.WithRestHeadersException { - ExceptionWithHeaders() { + WithHeadersException() { super("", header("n1", "v11", "v12"), header("n2", "v21", "v22")); } } diff --git a/core/src/test/java/org/elasticsearch/snapshots/RepositoriesTests.java b/core/src/test/java/org/elasticsearch/snapshots/RepositoriesTests.java index 74e99c995a2..f4989314f4b 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/RepositoriesTests.java +++ b/core/src/test/java/org/elasticsearch/snapshots/RepositoriesTests.java @@ -18,8 +18,6 @@ */ package org.elasticsearch.snapshots; -import com.google.common.collect.ImmutableList; - import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryResponse; import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse; import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse; diff --git a/dev-tools/src/main/resources/forbidden/all-signatures.txt b/dev-tools/src/main/resources/forbidden/all-signatures.txt index b67be9d69f4..cb4b2a43632 100644 --- a/dev-tools/src/main/resources/forbidden/all-signatures.txt +++ b/dev-tools/src/main/resources/forbidden/all-signatures.txt @@ -55,3 +55,9 @@ org.joda.time.DateTime#(int, int, int, int, int, int, int) org.joda.time.DateTime#now() com.google.common.collect.Iterators#emptyIterator() @ Use Collections.emptyIterator instead + +@defaultMessage Don't use java serialization - this can break BWC without noticing it +java.io.ObjectOutputStream +java.io.ObjectOutput +java.io.ObjectInputStream +java.io.ObjectInput \ No newline at end of file From fa016a2b0981c8d6d073cd6c9c1254450e882e12 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 29 Jun 2015 20:05:54 +0200 Subject: [PATCH 10/19] Don't implement Serializable in core classes We can't add this to forbidden API since literally everything implements this. Any API that would for instance use a String would not compile anymore. --- .../action/ShardOperationFailedException.java | 10 +--------- .../admin/cluster/node/info/PluginInfo.java | 3 +-- .../admin/cluster/node/info/PluginsInfo.java | 3 +-- .../cluster/block/ClusterBlock.java | 3 +-- .../cluster/metadata/SnapshotId.java | 3 +-- .../cluster/node/DiscoveryNode.java | 1 - .../cluster/routing/RoutingTableValidation.java | 3 +-- .../cluster/routing/ShardRouting.java | 3 +-- .../common/io/stream/StreamInput.java | 4 ++-- .../java/org/elasticsearch/common/text/Text.java | 3 +-- .../common/transport/TransportAddress.java | 1 - .../elasticsearch/common/unit/ByteSizeValue.java | 3 +-- .../org/elasticsearch/common/unit/SizeValue.java | 3 +-- .../org/elasticsearch/common/unit/TimeValue.java | 2 +- .../java/org/elasticsearch/http/HttpInfo.java | 3 +-- .../main/java/org/elasticsearch/index/Index.java | 3 +-- .../org/elasticsearch/index/shard/ShardId.java | 3 +-- .../elasticsearch/indices/NodeIndicesStats.java | 3 +-- .../org/elasticsearch/monitor/jvm/JvmInfo.java | 5 ++--- .../org/elasticsearch/monitor/jvm/JvmStats.java | 16 ++++++---------- .../monitor/network/NetworkInfo.java | 5 ++--- .../monitor/network/NetworkStats.java | 5 ++--- .../org/elasticsearch/monitor/os/OsInfo.java | 9 ++++----- .../org/elasticsearch/monitor/os/OsStats.java | 9 ++++----- .../monitor/process/ProcessInfo.java | 3 +-- .../monitor/process/ProcessStats.java | 7 +++---- .../elasticsearch/search/SearchShardTarget.java | 3 +-- .../elasticsearch/transport/TransportInfo.java | 3 +-- 28 files changed, 43 insertions(+), 79 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/ShardOperationFailedException.java b/core/src/main/java/org/elasticsearch/action/ShardOperationFailedException.java index 95cda257690..2eea6d3fb99 100644 --- a/core/src/main/java/org/elasticsearch/action/ShardOperationFailedException.java +++ b/core/src/main/java/org/elasticsearch/action/ShardOperationFailedException.java @@ -21,22 +21,14 @@ package org.elasticsearch.action; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexException; import org.elasticsearch.rest.RestStatus; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - /** * An exception indicating that a failure occurred performing an operation on the shard. * * */ -public interface ShardOperationFailedException extends Streamable, Serializable, ToXContent { +public interface ShardOperationFailedException extends Streamable, ToXContent { /** * The index the operation failed on. Might return null if it can't be derived. diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/PluginInfo.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/PluginInfo.java index 20c5f96f831..69d001220d1 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/PluginInfo.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/PluginInfo.java @@ -28,9 +28,8 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; -import java.io.Serializable; -public class PluginInfo implements Streamable, Serializable, ToXContent { +public class PluginInfo implements Streamable, ToXContent { public static final String DESCRIPTION_NOT_AVAILABLE = "No description found."; public static final String VERSION_NOT_AVAILABLE = "NA"; diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/PluginsInfo.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/PluginsInfo.java index 984559096e9..8e546f9dadf 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/PluginsInfo.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/PluginsInfo.java @@ -27,11 +27,10 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; -import java.io.Serializable; import java.util.ArrayList; import java.util.List; -public class PluginsInfo implements Streamable, Serializable, ToXContent { +public class PluginsInfo implements Streamable, ToXContent { static final class Fields { static final XContentBuilderString PLUGINS = new XContentBuilderString("plugins"); } diff --git a/core/src/main/java/org/elasticsearch/cluster/block/ClusterBlock.java b/core/src/main/java/org/elasticsearch/cluster/block/ClusterBlock.java index aee6c7f8fc4..39e1068f605 100644 --- a/core/src/main/java/org/elasticsearch/cluster/block/ClusterBlock.java +++ b/core/src/main/java/org/elasticsearch/cluster/block/ClusterBlock.java @@ -27,7 +27,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.RestStatus; import java.io.IOException; -import java.io.Serializable; import java.util.ArrayList; import java.util.EnumSet; import java.util.Locale; @@ -35,7 +34,7 @@ import java.util.Locale; /** * */ -public class ClusterBlock implements Serializable, Streamable, ToXContent { +public class ClusterBlock implements Streamable, ToXContent { private int id; diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/SnapshotId.java b/core/src/main/java/org/elasticsearch/cluster/metadata/SnapshotId.java index d8175c5ae6f..132145b0998 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/SnapshotId.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/SnapshotId.java @@ -24,12 +24,11 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import java.io.IOException; -import java.io.Serializable; /** * Snapshot ID - repository name + snapshot name */ -public class SnapshotId implements Serializable, Streamable { +public class SnapshotId implements Streamable { private String repository; diff --git a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java index 8a8cd819c40..4b4c765b14a 100644 --- a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -31,7 +31,6 @@ import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.transport.TransportAddressSerializers; import java.io.IOException; -import java.io.Serializable; import java.util.Map; import static org.elasticsearch.common.transport.TransportAddressSerializers.addressToStream; diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTableValidation.java b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTableValidation.java index 6a0eac27c57..bd1e283f436 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTableValidation.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTableValidation.java @@ -27,7 +27,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import java.io.IOException; -import java.io.Serializable; import java.util.List; import java.util.Map; @@ -39,7 +38,7 @@ import static com.google.common.collect.Maps.newHashMap; * Encapsulates the result of a routing table validation and provides access to * validation failures. */ -public class RoutingTableValidation implements Serializable, Streamable { +public class RoutingTableValidation implements Streamable { private boolean valid = true; diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java b/core/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java index f65b74dea30..3811a5fe7c2 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java @@ -29,7 +29,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.shard.ShardId; import java.io.IOException; -import java.io.Serializable; import java.util.Arrays; import java.util.List; @@ -37,7 +36,7 @@ import java.util.List; * {@link ShardRouting} immutably encapsulates information about shard * routings like id, state, version, etc. */ -public final class ShardRouting implements Streamable, Serializable, ToXContent { +public final class ShardRouting implements Streamable, ToXContent { protected String index; diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java index 5b7d4a4143a..82a32d69aa7 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java @@ -488,7 +488,7 @@ public abstract class StreamInput extends InputStream { case 0: return (T) ElasticsearchException.readException(this); case 1: - // nocommit - this sucks it would be nice to have a better way to construct those? + // this sucks it would be nice to have a better way to construct those? String msg = readOptionalString(); final int idx = msg.indexOf(" (resource="); String resource = msg.substring(idx + " (resource=".length(), msg.length()-1); @@ -520,7 +520,7 @@ public abstract class StreamInput extends InputStream { return (T) ElasticsearchException.readStackTrace(new EOFException(eofMessage), this); case 9: return (T) ElasticsearchException.readStackTrace(new SecurityException(readOptionalString(), readThrowable()), this); - case 10: // unknown -- // nocommit - should we use a dedicated exception + case 10: // unknown -- // C - should we use a dedicated exception return (T) ElasticsearchException.readStackTrace(new ElasticsearchException(readOptionalString(), readThrowable()), this); default: assert false : "no such exception for id: " + key; diff --git a/core/src/main/java/org/elasticsearch/common/text/Text.java b/core/src/main/java/org/elasticsearch/common/text/Text.java index 7c7db24552e..9fe1ea5f35d 100644 --- a/core/src/main/java/org/elasticsearch/common/text/Text.java +++ b/core/src/main/java/org/elasticsearch/common/text/Text.java @@ -20,14 +20,13 @@ package org.elasticsearch.common.text; import org.elasticsearch.common.bytes.BytesReference; -import java.io.Serializable; /** * Text represents a (usually) long text data. We use this abstraction instead of {@link String} * so we can represent it in a more optimized manner in memory as well as serializing it over the * network as well as converting it to json format. */ -public interface Text extends Comparable, Serializable { +public interface Text extends Comparable { /** * Are bytes available without the need to be converted into bytes when calling {@link #bytes()}. diff --git a/core/src/main/java/org/elasticsearch/common/transport/TransportAddress.java b/core/src/main/java/org/elasticsearch/common/transport/TransportAddress.java index 5bff0f9fdaa..1338b3bc1d8 100644 --- a/core/src/main/java/org/elasticsearch/common/transport/TransportAddress.java +++ b/core/src/main/java/org/elasticsearch/common/transport/TransportAddress.java @@ -21,7 +21,6 @@ package org.elasticsearch.common.transport; import org.elasticsearch.common.io.stream.Streamable; -import java.io.Serializable; /** * diff --git a/core/src/main/java/org/elasticsearch/common/unit/ByteSizeValue.java b/core/src/main/java/org/elasticsearch/common/unit/ByteSizeValue.java index ef2a71c8d6c..167a4849a53 100644 --- a/core/src/main/java/org/elasticsearch/common/unit/ByteSizeValue.java +++ b/core/src/main/java/org/elasticsearch/common/unit/ByteSizeValue.java @@ -28,11 +28,10 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.settings.Settings; import java.io.IOException; -import java.io.Serializable; import java.util.Locale; import java.util.Objects; -public class ByteSizeValue implements Serializable, Streamable { +public class ByteSizeValue implements Streamable { private long size; diff --git a/core/src/main/java/org/elasticsearch/common/unit/SizeValue.java b/core/src/main/java/org/elasticsearch/common/unit/SizeValue.java index 415326f7069..44d7155a2d2 100644 --- a/core/src/main/java/org/elasticsearch/common/unit/SizeValue.java +++ b/core/src/main/java/org/elasticsearch/common/unit/SizeValue.java @@ -27,12 +27,11 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import java.io.IOException; -import java.io.Serializable; /** * */ -public class SizeValue implements Serializable, Streamable { +public class SizeValue implements Streamable { private long size; diff --git a/core/src/main/java/org/elasticsearch/common/unit/TimeValue.java b/core/src/main/java/org/elasticsearch/common/unit/TimeValue.java index feafe529806..14b7d32338f 100644 --- a/core/src/main/java/org/elasticsearch/common/unit/TimeValue.java +++ b/core/src/main/java/org/elasticsearch/common/unit/TimeValue.java @@ -37,7 +37,7 @@ import java.util.Locale; import java.util.Objects; import java.util.concurrent.TimeUnit; -public class TimeValue implements Serializable, Streamable { +public class TimeValue implements Streamable { /** How many nano-seconds in one milli-second */ public static final long NSEC_PER_MSEC = 1000000; diff --git a/core/src/main/java/org/elasticsearch/http/HttpInfo.java b/core/src/main/java/org/elasticsearch/http/HttpInfo.java index da8bffd71c0..6b425d6f546 100644 --- a/core/src/main/java/org/elasticsearch/http/HttpInfo.java +++ b/core/src/main/java/org/elasticsearch/http/HttpInfo.java @@ -29,12 +29,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; -import java.io.Serializable; /** * */ -public class HttpInfo implements Streamable, Serializable, ToXContent { +public class HttpInfo implements Streamable, ToXContent { private BoundTransportAddress address; private long maxContentLength; diff --git a/core/src/main/java/org/elasticsearch/index/Index.java b/core/src/main/java/org/elasticsearch/index/Index.java index 123705080c7..4bf2f621446 100644 --- a/core/src/main/java/org/elasticsearch/index/Index.java +++ b/core/src/main/java/org/elasticsearch/index/Index.java @@ -24,12 +24,11 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import java.io.IOException; -import java.io.Serializable; /** * */ -public class Index implements Serializable, Streamable { +public class Index implements Streamable { private String name; diff --git a/core/src/main/java/org/elasticsearch/index/shard/ShardId.java b/core/src/main/java/org/elasticsearch/index/shard/ShardId.java index 91c8f61e1d9..2c0eb7c9e38 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/ShardId.java +++ b/core/src/main/java/org/elasticsearch/index/shard/ShardId.java @@ -25,12 +25,11 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.index.Index; import java.io.IOException; -import java.io.Serializable; /** * Allows for shard level components to be injected with the shard id. */ -public class ShardId implements Serializable, Streamable, Comparable { +public class ShardId implements Streamable, Comparable { private Index index; diff --git a/core/src/main/java/org/elasticsearch/indices/NodeIndicesStats.java b/core/src/main/java/org/elasticsearch/indices/NodeIndicesStats.java index 4845555d5fb..d7d625090aa 100644 --- a/core/src/main/java/org/elasticsearch/indices/NodeIndicesStats.java +++ b/core/src/main/java/org/elasticsearch/indices/NodeIndicesStats.java @@ -51,14 +51,13 @@ import org.elasticsearch.index.suggest.stats.SuggestStats; import org.elasticsearch.search.suggest.completion.CompletionStats; import java.io.IOException; -import java.io.Serializable; import java.util.List; import java.util.Map; /** * Global information on indices stats running on a specific node. */ -public class NodeIndicesStats implements Streamable, Serializable, ToXContent { +public class NodeIndicesStats implements Streamable, ToXContent { private CommonStats stats; private Map> statsByShard; diff --git a/core/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java b/core/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java index 047a59b0ead..a2b12ea5e50 100644 --- a/core/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java +++ b/core/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java @@ -29,7 +29,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; -import java.io.Serializable; import java.lang.management.*; import java.util.HashMap; import java.util.List; @@ -38,7 +37,7 @@ import java.util.Map; /** * */ -public class JvmInfo implements Streamable, Serializable, ToXContent { +public class JvmInfo implements Streamable, ToXContent { private static JvmInfo INSTANCE; @@ -349,7 +348,7 @@ public class JvmInfo implements Streamable, Serializable, ToXContent { out.writeStringArray(memoryPools); } - public static class Mem implements Streamable, Serializable { + public static class Mem implements Streamable { long heapInit = 0; long heapMax = 0; diff --git a/core/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java b/core/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java index f1d6e44a3ec..78417c7c41e 100644 --- a/core/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java +++ b/core/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java @@ -20,7 +20,6 @@ package org.elasticsearch.monitor.jvm; import com.google.common.collect.Iterators; -import org.elasticsearch.common.Booleans; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; @@ -31,19 +30,16 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; -import java.io.Serializable; import java.lang.management.*; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.concurrent.TimeUnit; /** * */ -public class JvmStats implements Streamable, Serializable, ToXContent { +public class JvmStats implements Streamable, ToXContent { private final static RuntimeMXBean runtimeMXBean; private final static MemoryMXBean memoryMXBean; @@ -318,7 +314,7 @@ public class JvmStats implements Streamable, Serializable, ToXContent { } } - public static class GarbageCollectors implements Streamable, Serializable, Iterable { + public static class GarbageCollectors implements Streamable, Iterable { GarbageCollector[] collectors; @@ -357,7 +353,7 @@ public class JvmStats implements Streamable, Serializable, ToXContent { } } - public static class GarbageCollector implements Streamable, Serializable { + public static class GarbageCollector implements Streamable { String name; long collectionCount; @@ -399,7 +395,7 @@ public class JvmStats implements Streamable, Serializable, ToXContent { } } - public static class Threads implements Streamable, Serializable { + public static class Threads implements Streamable { int count; int peakCount; @@ -434,7 +430,7 @@ public class JvmStats implements Streamable, Serializable, ToXContent { } } - public static class MemoryPool implements Streamable, Serializable { + public static class MemoryPool implements Streamable { String name; long used; @@ -500,7 +496,7 @@ public class JvmStats implements Streamable, Serializable, ToXContent { } } - public static class Mem implements Streamable, Serializable, Iterable { + public static class Mem implements Streamable, Iterable { long heapCommitted; long heapUsed; diff --git a/core/src/main/java/org/elasticsearch/monitor/network/NetworkInfo.java b/core/src/main/java/org/elasticsearch/monitor/network/NetworkInfo.java index 8638bdd2360..77c9c9460ba 100644 --- a/core/src/main/java/org/elasticsearch/monitor/network/NetworkInfo.java +++ b/core/src/main/java/org/elasticsearch/monitor/network/NetworkInfo.java @@ -27,12 +27,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; -import java.io.Serializable; /** * */ -public class NetworkInfo implements Streamable, Serializable, ToXContent { +public class NetworkInfo implements Streamable, ToXContent { public static final Interface NA_INTERFACE = new Interface(); @@ -99,7 +98,7 @@ public class NetworkInfo implements Streamable, Serializable, ToXContent { primary.writeTo(out); } - public static class Interface implements Streamable, Serializable { + public static class Interface implements Streamable { private String name = ""; private String address = ""; diff --git a/core/src/main/java/org/elasticsearch/monitor/network/NetworkStats.java b/core/src/main/java/org/elasticsearch/monitor/network/NetworkStats.java index 221a0915c72..a5d4671ef81 100644 --- a/core/src/main/java/org/elasticsearch/monitor/network/NetworkStats.java +++ b/core/src/main/java/org/elasticsearch/monitor/network/NetworkStats.java @@ -27,12 +27,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; -import java.io.Serializable; /** * */ -public class NetworkStats implements Streamable, Serializable, ToXContent { +public class NetworkStats implements Streamable, ToXContent { long timestamp; @@ -119,7 +118,7 @@ public class NetworkStats implements Streamable, Serializable, ToXContent { return tcp(); } - public static class Tcp implements Serializable, Streamable { + public static class Tcp implements Streamable { long activeOpens; long passiveOpens; diff --git a/core/src/main/java/org/elasticsearch/monitor/os/OsInfo.java b/core/src/main/java/org/elasticsearch/monitor/os/OsInfo.java index 75646c60b2d..1f3bc8b508a 100644 --- a/core/src/main/java/org/elasticsearch/monitor/os/OsInfo.java +++ b/core/src/main/java/org/elasticsearch/monitor/os/OsInfo.java @@ -28,12 +28,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; -import java.io.Serializable; /** * */ -public class OsInfo implements Streamable, Serializable, ToXContent { +public class OsInfo implements Streamable, ToXContent { long refreshInterval; @@ -188,7 +187,7 @@ public class OsInfo implements Streamable, Serializable, ToXContent { } } - public static class Swap implements Streamable, Serializable { + public static class Swap implements Streamable { long total = -1; @@ -222,7 +221,7 @@ public class OsInfo implements Streamable, Serializable, ToXContent { } - public static class Mem implements Streamable, Serializable { + public static class Mem implements Streamable { long total = -1; @@ -256,7 +255,7 @@ public class OsInfo implements Streamable, Serializable, ToXContent { } - public static class Cpu implements Streamable, Serializable, ToXContent { + public static class Cpu implements Streamable, ToXContent { String vendor = ""; String model = ""; diff --git a/core/src/main/java/org/elasticsearch/monitor/os/OsStats.java b/core/src/main/java/org/elasticsearch/monitor/os/OsStats.java index 44f43fb2ec8..c5dcab69b0e 100644 --- a/core/src/main/java/org/elasticsearch/monitor/os/OsStats.java +++ b/core/src/main/java/org/elasticsearch/monitor/os/OsStats.java @@ -29,13 +29,12 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; -import java.io.Serializable; import java.util.concurrent.TimeUnit; /** * */ -public class OsStats implements Streamable, Serializable, ToXContent { +public class OsStats implements Streamable, ToXContent { public static final double[] EMPTY_LOAD = new double[0]; @@ -249,7 +248,7 @@ public class OsStats implements Streamable, Serializable, ToXContent { } } - public static class Swap implements Streamable, Serializable { + public static class Swap implements Streamable { long free = -1; long used = -1; @@ -289,7 +288,7 @@ public class OsStats implements Streamable, Serializable, ToXContent { } } - public static class Mem implements Streamable, Serializable { + public static class Mem implements Streamable { long free = -1; short freePercent = -1; @@ -373,7 +372,7 @@ public class OsStats implements Streamable, Serializable, ToXContent { } } - public static class Cpu implements Streamable, Serializable { + public static class Cpu implements Streamable { short sys = -1; short user = -1; diff --git a/core/src/main/java/org/elasticsearch/monitor/process/ProcessInfo.java b/core/src/main/java/org/elasticsearch/monitor/process/ProcessInfo.java index 49d140e203b..8fd16d528fb 100644 --- a/core/src/main/java/org/elasticsearch/monitor/process/ProcessInfo.java +++ b/core/src/main/java/org/elasticsearch/monitor/process/ProcessInfo.java @@ -28,12 +28,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; -import java.io.Serializable; /** * */ -public class ProcessInfo implements Streamable, Serializable, ToXContent { +public class ProcessInfo implements Streamable, ToXContent { long refreshInterval; diff --git a/core/src/main/java/org/elasticsearch/monitor/process/ProcessStats.java b/core/src/main/java/org/elasticsearch/monitor/process/ProcessStats.java index c286b962de2..9777864a89a 100644 --- a/core/src/main/java/org/elasticsearch/monitor/process/ProcessStats.java +++ b/core/src/main/java/org/elasticsearch/monitor/process/ProcessStats.java @@ -29,12 +29,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; -import java.io.Serializable; /** * */ -public class ProcessStats implements Streamable, Serializable, ToXContent { +public class ProcessStats implements Streamable, ToXContent { long timestamp = -1; @@ -162,7 +161,7 @@ public class ProcessStats implements Streamable, Serializable, ToXContent { } } - public static class Mem implements Streamable, Serializable { + public static class Mem implements Streamable { long totalVirtual = -1; long resident = -1; @@ -216,7 +215,7 @@ public class ProcessStats implements Streamable, Serializable, ToXContent { } } - public static class Cpu implements Streamable, Serializable { + public static class Cpu implements Streamable { short percent = -1; long sys = -1; diff --git a/core/src/main/java/org/elasticsearch/search/SearchShardTarget.java b/core/src/main/java/org/elasticsearch/search/SearchShardTarget.java index c39515ec4c7..1a12751d396 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchShardTarget.java +++ b/core/src/main/java/org/elasticsearch/search/SearchShardTarget.java @@ -27,12 +27,11 @@ import org.elasticsearch.common.text.StringAndBytesText; import org.elasticsearch.common.text.Text; import java.io.IOException; -import java.io.Serializable; /** * The target that the search request was executed on. */ -public class SearchShardTarget implements Streamable, Serializable, Comparable { +public class SearchShardTarget implements Streamable, Comparable { private Text nodeId; private Text index; diff --git a/core/src/main/java/org/elasticsearch/transport/TransportInfo.java b/core/src/main/java/org/elasticsearch/transport/TransportInfo.java index 817d8a1332f..14add568205 100644 --- a/core/src/main/java/org/elasticsearch/transport/TransportInfo.java +++ b/core/src/main/java/org/elasticsearch/transport/TransportInfo.java @@ -30,13 +30,12 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; -import java.io.Serializable; import java.util.Map; /** * */ -public class TransportInfo implements Streamable, Serializable, ToXContent { +public class TransportInfo implements Streamable, ToXContent { private BoundTransportAddress address; private Map profileAddresses; From 62d29ff6a48027962f4f10cb47aef4ddbbf5540f Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 29 Jun 2015 20:39:04 +0200 Subject: [PATCH 11/19] simplify exception reading / writing - now use a named exception for unknonw exceptions --- .../elasticsearch/ElasticsearchException.java | 46 ++++++------- .../common/io/stream/StreamInput.java | 67 ++++++++++++++----- .../common/io/stream/StreamOutput.java | 16 +++-- 3 files changed, 84 insertions(+), 45 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/ElasticsearchException.java b/core/src/main/java/org/elasticsearch/ElasticsearchException.java index 479363b7462..362ec91d533 100644 --- a/core/src/main/java/org/elasticsearch/ElasticsearchException.java +++ b/core/src/main/java/org/elasticsearch/ElasticsearchException.java @@ -65,9 +65,8 @@ public class ElasticsearchException extends RuntimeException implements ToXConte } public ElasticsearchException(StreamInput in) throws IOException { - super(in.readOptionalString(), in.readThrowable()); //TODO readOptionalThrowable + super(in.readOptionalString(), in.readThrowable()); readStackTrace(this, in); - } /** @@ -166,8 +165,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte writeStackTraces(this, out); } - public static ElasticsearchException readException(StreamInput input) throws IOException { - final String name = input.readString(); + public static ElasticsearchException readException(StreamInput input, String name) throws IOException { Constructor elasticsearchException = MAPPING.get(name); if (elasticsearchException == null) { throw new IllegalStateException("unknown exception with name: " + name); @@ -179,18 +177,13 @@ public class ElasticsearchException extends RuntimeException implements ToXConte } } - public static void writeException(ElasticsearchException ex, StreamOutput output) throws IOException { - output.writeString(ex.getClass().getName()); - ex.writeTo(output); - } - /** * A base class for exceptions that should carry rest headers */ @SuppressWarnings("unchecked") public static class WithRestHeadersException extends ElasticsearchException implements HasRestHeaders { - private final ImmutableMap> headers; + private final Map> headers; public WithRestHeadersException(String msg, Tuple... headers) { super(msg); @@ -202,9 +195,9 @@ public class ElasticsearchException extends RuntimeException implements ToXConte int numKeys = in.readVInt(); ImmutableMap.Builder> builder = ImmutableMap.builder(); for (int i = 0; i < numKeys; i++) { - String key = in.readString(); - int numValues = in.readVInt(); - ArrayList headers = new ArrayList<>(numValues); + final String key = in.readString(); + final int numValues = in.readVInt(); + final ArrayList headers = new ArrayList<>(numValues); for (int j = 0; j < numValues; j++) { headers.add(in.readString()); } @@ -223,12 +216,11 @@ public class ElasticsearchException extends RuntimeException implements ToXConte for (String v : entry.getValue()) { out.writeString(v); } - } } @Override - public ImmutableMap> getHeaders() { + public Map> getHeaders() { return headers; } @@ -236,7 +228,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte return Tuple.tuple(name, values); } - private static ImmutableMap> headers(Tuple... headers) { + private static Map> headers(Tuple... headers) { Map> map = Maps.newHashMap(); for (Tuple header : headers) { List list = map.get(header.v1()); @@ -353,15 +345,19 @@ public class ElasticsearchException extends RuntimeException implements ToXConte return ExceptionsHelper.detailedMessage(this).trim(); } + /** + * Deserializes stacktrace elements as well as suppressed exceptions from the given output stream and + * adds it to the given exception. + */ public static T readStackTrace(T throwable, StreamInput in) throws IOException { - int stackTraceElements = in.readVInt(); + final int stackTraceElements = in.readVInt(); StackTraceElement[] stackTrace = new StackTraceElement[stackTraceElements]; for (int i = 0; i < stackTraceElements; i++) { - String declaringClasss = in.readString(); - String fielName = in.readString(); - String methodName = in.readString(); - int lineNumber = in.readVInt(); - stackTrace[i] = new StackTraceElement(declaringClasss,methodName, fielName, lineNumber); + final String declaringClasss = in.readString(); + final String fileName = in.readString(); + final String methodName = in.readString(); + final int lineNumber = in.readVInt(); + stackTrace[i] = new StackTraceElement(declaringClasss,methodName, fileName, lineNumber); } throwable.setStackTrace(stackTrace); @@ -372,6 +368,9 @@ public class ElasticsearchException extends RuntimeException implements ToXConte return throwable; } + /** + * Serializes the given exceptions stacktrace elements as well as it's suppressed exceptions to the given output stream. + */ public static T writeStackTraces(T throwable, StreamOutput out) throws IOException { StackTraceElement[] stackTrace = throwable.getStackTrace(); out.writeVInt(stackTrace.length); @@ -533,7 +532,8 @@ public class ElasticsearchException extends RuntimeException implements ToXConte org.elasticsearch.ElasticsearchParseException.class, org.elasticsearch.action.PrimaryMissingActionException.class, org.elasticsearch.index.engine.CreateFailedEngineException.class, - org.elasticsearch.index.shard.IllegalIndexShardStateException.class + org.elasticsearch.index.shard.IllegalIndexShardStateException.class, + org.elasticsearch.common.io.stream.StreamInput.NamedException.class }; Map> mapping = new HashMap<>(); diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java index 82a32d69aa7..f2d5416a6d0 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java @@ -39,6 +39,9 @@ import java.io.*; import java.util.*; import java.util.regex.Pattern; +import static org.elasticsearch.ElasticsearchException.readException; +import static org.elasticsearch.ElasticsearchException.readStackTrace; + /** * */ @@ -486,42 +489,41 @@ public abstract class StreamInput extends InputStream { int key = readVInt(); switch (key) { case 0: - return (T) ElasticsearchException.readException(this); + final String name = readString(); + return (T) readException(this, name); case 1: // this sucks it would be nice to have a better way to construct those? String msg = readOptionalString(); final int idx = msg.indexOf(" (resource="); - String resource = msg.substring(idx + " (resource=".length(), msg.length()-1); + final String resource = msg.substring(idx + " (resource=".length(), msg.length()-1); msg = msg.substring(0, idx); - return (T) ElasticsearchException.readStackTrace(new CorruptIndexException(msg, resource, readThrowable()), this); // TODO add a string throwable ctor to this? + return (T) readStackTrace(new CorruptIndexException(msg, resource, readThrowable()), this); // Lucene 5.3 will have getters for all these case 2: - String itnMessage = readOptionalString(); + final String itnMessage = readOptionalString(); readThrowable(); - return (T) ElasticsearchException.readStackTrace(new IndexFormatTooNewException(itnMessage, -1, -1, -1), this); + return (T) readStackTrace(new IndexFormatTooNewException(itnMessage, -1, -1, -1), this); case 3: - String itoMessage = readOptionalString(); + final String itoMessage = readOptionalString(); readThrowable(); - return (T) ElasticsearchException.readStackTrace(new IndexFormatTooOldException(itoMessage, -1, -1, -1), this); + return (T) readStackTrace(new IndexFormatTooOldException(itoMessage, -1, -1, -1), this); case 4: - String npeMessage = readOptionalString(); + final String npeMessage = readOptionalString(); readThrowable(); - return (T) ElasticsearchException.readStackTrace(new NullPointerException(npeMessage), this); + return (T) readStackTrace(new NullPointerException(npeMessage), this); case 5: - String nfeMessage = readOptionalString(); + final String nfeMessage = readOptionalString(); readThrowable(); - return (T) ElasticsearchException.readStackTrace(new NumberFormatException(nfeMessage), this); + return (T) readStackTrace(new NumberFormatException(nfeMessage), this); case 6: - return (T) ElasticsearchException.readStackTrace(new IllegalArgumentException(readOptionalString(), readThrowable()), this); + return (T) readStackTrace(new IllegalArgumentException(readOptionalString(), readThrowable()), this); case 7: - return (T) ElasticsearchException.readStackTrace(new IllegalStateException(readOptionalString(), readThrowable()), this); + return (T) readStackTrace(new IllegalStateException(readOptionalString(), readThrowable()), this); case 8: - String eofMessage = readOptionalString(); + final String eofMessage = readOptionalString(); readThrowable(); - return (T) ElasticsearchException.readStackTrace(new EOFException(eofMessage), this); + return (T) readStackTrace(new EOFException(eofMessage), this); case 9: - return (T) ElasticsearchException.readStackTrace(new SecurityException(readOptionalString(), readThrowable()), this); - case 10: // unknown -- // C - should we use a dedicated exception - return (T) ElasticsearchException.readStackTrace(new ElasticsearchException(readOptionalString(), readThrowable()), this); + return (T) readStackTrace(new SecurityException(readOptionalString(), readThrowable()), this); default: assert false : "no such exception for id: " + key; } @@ -544,4 +546,33 @@ public abstract class StreamInput extends InputStream { return new InputStreamStreamInput(new ByteArrayInputStream(bytes, offset, length)); } + public static class NamedException extends ElasticsearchException { + + private final String name; + + public NamedException(String name, String msg, Throwable cause) { + super(msg, cause); + if (name == null) { + throw new IllegalArgumentException("name must not be null"); + } + this.name = name; + } + + public NamedException(StreamInput in) throws IOException { + super(in); + name = in.readString(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeString(name); + } + + @Override + protected String getExceptionName() { + return Strings.toUnderscoreCase(name); + } + } + } diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java index a98371acc97..0dfdfbb3f8c 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java @@ -456,9 +456,7 @@ public abstract class StreamOutput extends OutputStream { } else { writeBoolean(true); if (throwable instanceof ElasticsearchException) { - writeVInt(0); - ElasticsearchException.writeException((ElasticsearchException) throwable, this); - return; + } else if (throwable instanceof CorruptIndexException) { writeVInt(1); } else if (throwable instanceof IndexFormatTooNewException) { @@ -478,7 +476,17 @@ public abstract class StreamOutput extends OutputStream { } else if (throwable instanceof SecurityException) { writeVInt(9); } else { - writeVInt(10); // unknown + ElasticsearchException ex; + if (throwable instanceof ElasticsearchException) { + ex = (ElasticsearchException) throwable; + } else { + ex = new StreamInput.NamedException(ElasticsearchException.getExceptionName(throwable), throwable.getMessage(), throwable.getCause()); + } + writeVInt(0); + writeString(ex.getClass().getName()); + ex.writeTo(this); + return; + } writeOptionalString(throwable.getMessage()); writeThrowable(throwable.getCause()); From c4f15c2c91cdb3476c542581d1f2ff70a39b064a Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 29 Jun 2015 23:22:19 +0200 Subject: [PATCH 12/19] add dedicated unittests for exceptions that have a writeTo method (custom serialization) --- .../action/RoutingMissingException.java | 4 + .../search/SearchPhaseExecutionException.java | 5 +- .../breaker/CircuitBreakingException.java | 8 + .../common/io/stream/StreamOutput.java | 4 +- .../engine/CreateFailedEngineException.java | 11 +- .../engine/IndexFailedEngineException.java | 11 +- .../index/engine/InternalEngine.java | 4 +- .../index/engine/RecoveryEngineException.java | 2 +- .../index/mapper/MergeMappingException.java | 4 +- .../RecoverFilesRecoveryException.java | 2 + .../percolator/PercolateException.java | 2 + .../alias/delete/AliasesMissingException.java | 2 +- .../search/SearchContextException.java | 7 +- .../elasticsearch/search/SearchException.java | 3 +- .../warmer/IndexWarmerMissingException.java | 2 +- .../ExceptionRegistrationTests.java | 127 ----- .../ExceptionSerializationTests.java | 538 ++++++++++++++++++ 17 files changed, 584 insertions(+), 152 deletions(-) delete mode 100644 core/src/test/java/org/elasticsearch/ExceptionRegistrationTests.java create mode 100644 core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java diff --git a/core/src/main/java/org/elasticsearch/action/RoutingMissingException.java b/core/src/main/java/org/elasticsearch/action/RoutingMissingException.java index f5ed1f54aff..920d48b952a 100644 --- a/core/src/main/java/org/elasticsearch/action/RoutingMissingException.java +++ b/core/src/main/java/org/elasticsearch/action/RoutingMissingException.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.rest.RestStatus; import java.io.IOException; +import java.util.Objects; /** * @@ -39,6 +40,9 @@ public class RoutingMissingException extends ElasticsearchException { public RoutingMissingException(String index, String type, String id) { super("routing is required for [" + index + "]/[" + type + "]/[" + id + "]"); + Objects.requireNonNull(index, "index must not be null"); + Objects.requireNonNull(type, "type must not be null"); + Objects.requireNonNull(id, "id must not be null"); this.index = index; this.type = type; this.id = id; diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java b/core/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java index 4821cade3a2..a8d27c49d8f 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java @@ -37,7 +37,6 @@ import java.util.*; */ public class SearchPhaseExecutionException extends ElasticsearchException { private final String phaseName; - private final ShardSearchFailure[] shardFailures; public SearchPhaseExecutionException(String phaseName, String msg, ShardSearchFailure[] shardFailures) { @@ -144,4 +143,8 @@ public class SearchPhaseExecutionException extends ElasticsearchException { public String toString() { return buildMessage(phaseName, getMessage(), shardFailures); } + + public String getPhaseName() { + return phaseName; + } } diff --git a/core/src/main/java/org/elasticsearch/common/breaker/CircuitBreakingException.java b/core/src/main/java/org/elasticsearch/common/breaker/CircuitBreakingException.java index d35bac1f3d0..8347e54d4bd 100644 --- a/core/src/main/java/org/elasticsearch/common/breaker/CircuitBreakingException.java +++ b/core/src/main/java/org/elasticsearch/common/breaker/CircuitBreakingException.java @@ -21,6 +21,7 @@ package org.elasticsearch.common.breaker; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; @@ -64,4 +65,11 @@ public class CircuitBreakingException extends ElasticsearchException { public long getByteLimit() { return this.byteLimit; } + + @Override + protected void innerToXContent(XContentBuilder builder, Params params) throws IOException { + builder.field("bytes_wanted", bytesWanted); + builder.field("bytes_limit", byteLimit); + super.innerToXContent(builder, params); + } } diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java index 0dfdfbb3f8c..57a0585526d 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java @@ -455,9 +455,7 @@ public abstract class StreamOutput extends OutputStream { writeBoolean(false); } else { writeBoolean(true); - if (throwable instanceof ElasticsearchException) { - - } else if (throwable instanceof CorruptIndexException) { + if (throwable instanceof CorruptIndexException) { writeVInt(1); } else if (throwable instanceof IndexFormatTooNewException) { writeVInt(2); diff --git a/core/src/main/java/org/elasticsearch/index/engine/CreateFailedEngineException.java b/core/src/main/java/org/elasticsearch/index/engine/CreateFailedEngineException.java index 1214ba9eff4..32d9ee620c8 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/CreateFailedEngineException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/CreateFailedEngineException.java @@ -24,6 +24,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.index.shard.ShardId; import java.io.IOException; +import java.util.Objects; /** * @@ -34,10 +35,12 @@ public class CreateFailedEngineException extends EngineException { private final String id; - public CreateFailedEngineException(ShardId shardId, Engine.Create create, Throwable cause) { - super(shardId, "Create failed for [" + create.type() + "#" + create.id() + "]", cause); - this.type = create.type(); - this.id = create.id(); + public CreateFailedEngineException(ShardId shardId, String type, String id, Throwable cause) { + super(shardId, "Create failed for [" + type + "#" + id + "]", cause); + Objects.requireNonNull(type, "type must not be null"); + Objects.requireNonNull(id, "id must not be null"); + this.type = type; + this.id = id; } public CreateFailedEngineException(StreamInput in) throws IOException{ diff --git a/core/src/main/java/org/elasticsearch/index/engine/IndexFailedEngineException.java b/core/src/main/java/org/elasticsearch/index/engine/IndexFailedEngineException.java index 09de2386976..4728b7f899a 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/IndexFailedEngineException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/IndexFailedEngineException.java @@ -24,6 +24,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.index.shard.ShardId; import java.io.IOException; +import java.util.Objects; /** * @@ -34,10 +35,12 @@ public class IndexFailedEngineException extends EngineException { private final String id; - public IndexFailedEngineException(ShardId shardId, Engine.Index index, Throwable cause) { - super(shardId, "Index failed for [" + index.type() + "#" + index.id() + "]", cause); - this.type = index.type(); - this.id = index.id(); + public IndexFailedEngineException(ShardId shardId, String type, String id, Throwable cause) { + super(shardId, "Index failed for [" + type + "#" + id + "]", cause); + Objects.requireNonNull(type, "type must not be null"); + Objects.requireNonNull(id, "id must not be null"); + this.type = type; + this.id = id; } public IndexFailedEngineException(StreamInput in) throws IOException{ diff --git a/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java b/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java index 1ebdb6ef73e..fe8fdab090f 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java +++ b/core/src/main/java/org/elasticsearch/index/engine/InternalEngine.java @@ -335,7 +335,7 @@ public class InternalEngine extends Engine { } } catch (OutOfMemoryError | IllegalStateException | IOException t) { maybeFailEngine("create", t); - throw new CreateFailedEngineException(shardId, create, t); + throw new CreateFailedEngineException(shardId, create.type(), create.id(), t); } checkVersionMapRefresh(); } @@ -441,7 +441,7 @@ public class InternalEngine extends Engine { } } catch (OutOfMemoryError | IllegalStateException | IOException t) { maybeFailEngine("index", t); - throw new IndexFailedEngineException(shardId, index, t); + throw new IndexFailedEngineException(shardId, index.type(), index.id(), t); } checkVersionMapRefresh(); return created; diff --git a/core/src/main/java/org/elasticsearch/index/engine/RecoveryEngineException.java b/core/src/main/java/org/elasticsearch/index/engine/RecoveryEngineException.java index ee7468bdd1d..d55ed1d4189 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/RecoveryEngineException.java +++ b/core/src/main/java/org/elasticsearch/index/engine/RecoveryEngineException.java @@ -39,7 +39,7 @@ public class RecoveryEngineException extends EngineException { public RecoveryEngineException(StreamInput in) throws IOException{ super(in); - phase = in.readByte(); + phase = in.readInt(); } @Override diff --git a/core/src/main/java/org/elasticsearch/index/mapper/MergeMappingException.java b/core/src/main/java/org/elasticsearch/index/mapper/MergeMappingException.java index 912d4c985b8..4a5e75fcb56 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/MergeMappingException.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/MergeMappingException.java @@ -25,16 +25,18 @@ import org.elasticsearch.rest.RestStatus; import java.io.IOException; import java.util.Arrays; +import java.util.Objects; /** * */ -public class MergeMappingException extends MapperException { +public final class MergeMappingException extends MapperException { private final String[] failures; public MergeMappingException(String[] failures) { super("Merge failed with failures {" + Arrays.toString(failures) + "}"); + Objects.requireNonNull(failures, "failures must be non-null"); this.failures = failures; } diff --git a/core/src/main/java/org/elasticsearch/indices/recovery/RecoverFilesRecoveryException.java b/core/src/main/java/org/elasticsearch/indices/recovery/RecoverFilesRecoveryException.java index dea6e08e9cf..508e52f3590 100644 --- a/core/src/main/java/org/elasticsearch/indices/recovery/RecoverFilesRecoveryException.java +++ b/core/src/main/java/org/elasticsearch/indices/recovery/RecoverFilesRecoveryException.java @@ -27,6 +27,7 @@ import org.elasticsearch.index.shard.IndexShardException; import org.elasticsearch.index.shard.ShardId; import java.io.IOException; +import java.util.Objects; /** * @@ -39,6 +40,7 @@ public class RecoverFilesRecoveryException extends IndexShardException implement public RecoverFilesRecoveryException(ShardId shardId, int numberOfFiles, ByteSizeValue totalFilesSize, Throwable cause) { super(shardId, "Failed to transfer [" + numberOfFiles + "] files with total size of [" + totalFilesSize + "]", cause); + Objects.requireNonNull(totalFilesSize, "totalFilesSize must not be null"); this.numberOfFiles = numberOfFiles; this.totalFilesSize = totalFilesSize; } diff --git a/core/src/main/java/org/elasticsearch/percolator/PercolateException.java b/core/src/main/java/org/elasticsearch/percolator/PercolateException.java index 6b9b035ca12..81a708a75ec 100644 --- a/core/src/main/java/org/elasticsearch/percolator/PercolateException.java +++ b/core/src/main/java/org/elasticsearch/percolator/PercolateException.java @@ -26,6 +26,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.index.shard.ShardId; import java.io.IOException; +import java.util.Objects; /** * Exception during percolating document(s) at runtime. @@ -36,6 +37,7 @@ public class PercolateException extends ElasticsearchException implements Elasti public PercolateException(ShardId shardId, String msg, Throwable cause) { super(msg, cause); + Objects.requireNonNull(shardId, "shardId must not be null"); this.shardId = shardId; } diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesMissingException.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesMissingException.java index daf6679d754..d6ac3042d21 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesMissingException.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/delete/AliasesMissingException.java @@ -34,7 +34,7 @@ public class AliasesMissingException extends ElasticsearchException { private final String[] names; public AliasesMissingException(String... names) { - super("aliases [" + Arrays.toString(names) + "] missing"); + super("aliases " + Arrays.toString(names) + " missing"); this.names = names; } diff --git a/core/src/main/java/org/elasticsearch/search/SearchContextException.java b/core/src/main/java/org/elasticsearch/search/SearchContextException.java index 4fa1750d321..2dc25a50373 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchContextException.java +++ b/core/src/main/java/org/elasticsearch/search/SearchContextException.java @@ -30,18 +30,15 @@ import java.io.IOException; public class SearchContextException extends SearchException { public SearchContextException(SearchContext context, String msg) { - super(context.shardTarget(), buildMessage(context, msg)); + super(context.shardTarget(), msg); } public SearchContextException(SearchContext context, String msg, Throwable t) { - super(context.shardTarget(), buildMessage(context, msg), t); + super(context.shardTarget(), msg, t); } public SearchContextException(StreamInput in) throws IOException { super(in); } - private static String buildMessage(SearchContext context, String msg) { - return msg; - } } diff --git a/core/src/main/java/org/elasticsearch/search/SearchException.java b/core/src/main/java/org/elasticsearch/search/SearchException.java index ac41fe9caed..ad335add38f 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchException.java +++ b/core/src/main/java/org/elasticsearch/search/SearchException.java @@ -33,8 +33,7 @@ public class SearchException extends ElasticsearchException { private final SearchShardTarget shardTarget; public SearchException(SearchShardTarget shardTarget, String msg) { - super(msg); - this.shardTarget = shardTarget; + this(shardTarget, msg, null); } public SearchException(SearchShardTarget shardTarget, String msg, Throwable cause) { diff --git a/core/src/main/java/org/elasticsearch/search/warmer/IndexWarmerMissingException.java b/core/src/main/java/org/elasticsearch/search/warmer/IndexWarmerMissingException.java index 98459ea7c5c..1253a24544d 100644 --- a/core/src/main/java/org/elasticsearch/search/warmer/IndexWarmerMissingException.java +++ b/core/src/main/java/org/elasticsearch/search/warmer/IndexWarmerMissingException.java @@ -34,7 +34,7 @@ public class IndexWarmerMissingException extends ElasticsearchException { private final String[] names; public IndexWarmerMissingException(String... names) { - super("index_warmer [" + Arrays.toString(names) + "] missing"); + super("index_warmer " + Arrays.toString(names) + " missing"); this.names = names; } diff --git a/core/src/test/java/org/elasticsearch/ExceptionRegistrationTests.java b/core/src/test/java/org/elasticsearch/ExceptionRegistrationTests.java deleted file mode 100644 index 3493b57776d..00000000000 --- a/core/src/test/java/org/elasticsearch/ExceptionRegistrationTests.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch; - -import com.google.common.collect.Sets; -import org.elasticsearch.common.io.PathUtils; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.test.ElasticsearchTestCase; - -import java.io.IOException; -import java.lang.reflect.Modifier; -import java.net.URISyntaxException; -import java.nio.file.FileVisitResult; -import java.nio.file.FileVisitor; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.HashSet; -import java.util.Set; - -public class ExceptionRegistrationTests extends ElasticsearchTestCase { - - public void testExceptionRegistration() - throws ClassNotFoundException, IOException, URISyntaxException { - final Set notRegistered = new HashSet<>(); - final Set registered = new HashSet<>(); - final String path = "/org/elasticsearch"; - final Path startPath = PathUtils.get(ElasticsearchException.class.getProtectionDomain().getCodeSource().getLocation().toURI()).resolve("org").resolve("elasticsearch"); - final Set ignore = Sets.newHashSet( - org.elasticsearch.test.rest.parser.RestTestParseException.class, - org.elasticsearch.index.query.TestQueryParsingException.class, - org.elasticsearch.test.rest.client.RestException.class, - org.elasticsearch.common.util.CancellableThreadsTest.CustomException.class, - org.elasticsearch.rest.BytesRestResponseTests.WithHeadersException.class, - org.elasticsearch.client.AbstractClientHeadersTests.InternalException.class); - FileVisitor visitor = new FileVisitor() { - private Path pkgPrefix = PathUtils.get(path).getParent(); - - @Override - public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { - Path next = pkgPrefix.resolve(dir.getFileName()); - if (ignore.contains(next)) { - return FileVisitResult.SKIP_SUBTREE; - } - pkgPrefix = next; - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - try { - String filename = file.getFileName().toString(); - if (filename.endsWith(".class")) { - Class clazz = loadClass(filename); - if (ignore.contains(clazz) == false) { - if (Modifier.isAbstract(clazz.getModifiers()) == false && Modifier.isInterface(clazz.getModifiers()) == false && isEsException(clazz)) { - if (ElasticsearchException.MAPPING.containsKey(clazz.getName()) == false && ElasticsearchException.class.equals(clazz.getEnclosingClass()) == false) { - notRegistered.add(clazz); - } else if (ElasticsearchException.MAPPING.containsKey(clazz.getName())) { - registered.add(clazz.getName()); - } - } - } - - } - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } - return FileVisitResult.CONTINUE; - } - - private boolean isEsException(Class clazz) { - return ElasticsearchException.class.isAssignableFrom(clazz); - } - - private Class loadClass(String filename) throws ClassNotFoundException { - StringBuilder pkg = new StringBuilder(); - for (Path p : pkgPrefix) { - pkg.append(p.getFileName().toString()).append("."); - } - pkg.append(filename.substring(0, filename.length() - 6)); - return Thread.currentThread().getContextClassLoader().loadClass(pkg.toString()); - } - - @Override - public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { - throw exc; - } - - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { - pkgPrefix = pkgPrefix.getParent(); - return FileVisitResult.CONTINUE; - } - }; - Files.walkFileTree(startPath, visitor); - final Path testStartPath = PathUtils.get(ExceptionRegistrationTests.class.getResource(path).toURI()); - Files.walkFileTree(testStartPath, visitor); - assertTrue(notRegistered.remove(TestException.class)); - assertTrue("Classes subclassing ElasticsearchException must be registered \n" + notRegistered.toString(), - notRegistered.isEmpty()); - assertTrue(registered.removeAll(ElasticsearchException.MAPPING.keySet())); // check - assertEquals(registered.toString(), 0 ,registered.size()); - } - - public static final class TestException extends ElasticsearchException { - public TestException(StreamInput in) throws IOException{ - super(in); - } - } -} diff --git a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java new file mode 100644 index 00000000000..8c0088a78cf --- /dev/null +++ b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java @@ -0,0 +1,538 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; +import org.elasticsearch.action.FailedNodeException; +import org.elasticsearch.action.RoutingMissingException; +import org.elasticsearch.action.TimestampParsingException; +import org.elasticsearch.action.search.SearchPhaseExecutionException; +import org.elasticsearch.action.search.ShardSearchFailure; +import org.elasticsearch.cluster.block.ClusterBlock; +import org.elasticsearch.cluster.block.ClusterBlockException; +import org.elasticsearch.cluster.metadata.SnapshotId; +import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.routing.*; +import org.elasticsearch.common.breaker.CircuitBreakingException; +import org.elasticsearch.common.io.PathUtils; +import org.elasticsearch.common.io.stream.*; +import org.elasticsearch.common.transport.InetSocketTransportAddress; +import org.elasticsearch.common.transport.LocalTransportAddress; +import org.elasticsearch.common.unit.ByteSizeValue; +import org.elasticsearch.common.xcontent.XContentLocation; +import org.elasticsearch.discovery.DiscoverySettings; +import org.elasticsearch.index.AlreadyExpiredException; +import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexException; +import org.elasticsearch.index.engine.CreateFailedEngineException; +import org.elasticsearch.index.engine.IndexFailedEngineException; +import org.elasticsearch.index.engine.RecoveryEngineException; +import org.elasticsearch.index.mapper.MergeMappingException; +import org.elasticsearch.index.query.QueryParsingException; +import org.elasticsearch.index.shard.*; +import org.elasticsearch.indices.IndexTemplateAlreadyExistsException; +import org.elasticsearch.indices.IndexTemplateMissingException; +import org.elasticsearch.indices.InvalidIndexTemplateException; +import org.elasticsearch.indices.recovery.RecoverFilesRecoveryException; +import org.elasticsearch.percolator.PercolateException; +import org.elasticsearch.repositories.RepositoryException; +import org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesMissingException; +import org.elasticsearch.search.SearchContextMissingException; +import org.elasticsearch.search.SearchException; +import org.elasticsearch.search.SearchParseException; +import org.elasticsearch.search.SearchShardTarget; +import org.elasticsearch.search.internal.SearchContext; +import org.elasticsearch.search.warmer.IndexWarmerMissingException; +import org.elasticsearch.snapshots.SnapshotException; +import org.elasticsearch.test.ElasticsearchTestCase; +import org.elasticsearch.test.TestSearchContext; +import org.elasticsearch.transport.ActionNotFoundTransportException; +import org.elasticsearch.transport.ActionTransportException; +import org.elasticsearch.transport.ConnectTransportException; + +import java.io.IOException; +import java.lang.reflect.Modifier; +import java.net.URISyntaxException; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.HashSet; +import java.util.Set; + +public class ExceptionSerializationTests extends ElasticsearchTestCase { + + public void testExceptionRegistration() + throws ClassNotFoundException, IOException, URISyntaxException { + final Set notRegistered = new HashSet<>(); + final Set hasDedicatedWrite = new HashSet<>(); + final Set registered = new HashSet<>(); + final String path = "/org/elasticsearch"; + final Path startPath = PathUtils.get(ElasticsearchException.class.getProtectionDomain().getCodeSource().getLocation().toURI()).resolve("org").resolve("elasticsearch"); + final Set ignore = Sets.newHashSet( + org.elasticsearch.test.rest.parser.RestTestParseException.class, + org.elasticsearch.index.query.TestQueryParsingException.class, + org.elasticsearch.test.rest.client.RestException.class, + org.elasticsearch.common.util.CancellableThreadsTest.CustomException.class, + org.elasticsearch.rest.BytesRestResponseTests.WithHeadersException.class, + org.elasticsearch.client.AbstractClientHeadersTests.InternalException.class); + FileVisitor visitor = new FileVisitor() { + private Path pkgPrefix = PathUtils.get(path).getParent(); + + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + Path next = pkgPrefix.resolve(dir.getFileName()); + if (ignore.contains(next)) { + return FileVisitResult.SKIP_SUBTREE; + } + pkgPrefix = next; + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + try { + String filename = file.getFileName().toString(); + if (filename.endsWith(".class")) { + Class clazz = loadClass(filename); + if (ignore.contains(clazz) == false) { + if (Modifier.isAbstract(clazz.getModifiers()) == false && Modifier.isInterface(clazz.getModifiers()) == false && isEsException(clazz)) { + if (ElasticsearchException.MAPPING.containsKey(clazz.getName()) == false && ElasticsearchException.class.equals(clazz.getEnclosingClass()) == false) { + notRegistered.add(clazz); + } else if (ElasticsearchException.MAPPING.containsKey(clazz.getName())) { + registered.add(clazz.getName()); + try { + if (clazz.getDeclaredMethod("writeTo", StreamOutput.class) != null) { + hasDedicatedWrite.add(clazz); + } + } catch (Exception e) { + // fair enough + } + + } + } + } + + } + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + return FileVisitResult.CONTINUE; + } + + private boolean isEsException(Class clazz) { + return ElasticsearchException.class.isAssignableFrom(clazz); + } + + private Class loadClass(String filename) throws ClassNotFoundException { + StringBuilder pkg = new StringBuilder(); + for (Path p : pkgPrefix) { + pkg.append(p.getFileName().toString()).append("."); + } + pkg.append(filename.substring(0, filename.length() - 6)); + return Thread.currentThread().getContextClassLoader().loadClass(pkg.toString()); + } + + @Override + public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { + throw exc; + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + pkgPrefix = pkgPrefix.getParent(); + return FileVisitResult.CONTINUE; + } + }; + + Files.walkFileTree(startPath, visitor); + final Path testStartPath = PathUtils.get(ExceptionSerializationTests.class.getResource(path).toURI()); + Files.walkFileTree(testStartPath, visitor); + assertTrue(notRegistered.remove(TestException.class)); + assertTrue("Classes subclassing ElasticsearchException must be registered \n" + notRegistered.toString(), + notRegistered.isEmpty()); + assertTrue(registered.removeAll(ElasticsearchException.MAPPING.keySet())); // check + assertEquals(registered.toString(), 0, registered.size()); + } + + public static final class TestException extends ElasticsearchException { + public TestException(StreamInput in) throws IOException{ + super(in); + } + } + + private T serialize(T exception) throws IOException { + BytesStreamOutput out = new BytesStreamOutput(); + out.writeThrowable(exception); + StreamInput in = StreamInput.wrap(out.bytes()); + return in.readThrowable(); + } + + public void testIllegalShardRoutingStateException() throws IOException { + ShardRouting routing = new ShardRouting("test", 0, "xyz", "def", false, ShardRoutingState.STARTED, 0); + IllegalShardRoutingStateException serialize = serialize(new IllegalShardRoutingStateException(routing, "foo", new NullPointerException())); + assertNotNull(serialize.shard()); + assertEquals(routing, serialize.shard()); + assertEquals("[test][0], node[xyz], relocating [def], [R], s[STARTED]: foo", serialize.getMessage()); + assertTrue(serialize.getCause() instanceof NullPointerException); + + serialize = serialize(new IllegalShardRoutingStateException(routing, "bar", null)); + assertNotNull(serialize.shard()); + assertEquals(routing, serialize.shard()); + assertEquals("[test][0], node[xyz], relocating [def], [R], s[STARTED]: bar", serialize.getMessage()); + assertNull(serialize.getCause()); + } + + public void testQueryParsingException() throws IOException { + QueryParsingException ex = serialize(new QueryParsingException(new Index("foo"), 1, 2, "fobar", null)); + assertEquals(ex.index(), new Index("foo")); + assertEquals(ex.getMessage(), "fobar"); + assertEquals(ex.getLineNumber(),1); + assertEquals(ex.getColumnNumber(), 2); + + ex = serialize(new QueryParsingException(null, 1, 2, null, null)); + assertNull(ex.index()); + assertNull(ex.getMessage()); + assertEquals(ex.getLineNumber(),1); + assertEquals(ex.getColumnNumber(), 2); + } + + public void testSearchException() throws IOException { + SearchShardTarget target = new SearchShardTarget("foo", "bar", 1); + SearchException ex = serialize(new SearchException(target, "hello world")); + assertEquals(target, ex.shard()); + assertEquals(ex.getMessage(), "hello world"); + + ex = serialize(new SearchException(null, "hello world", new NullPointerException())); + assertNull(ex.shard()); + assertEquals(ex.getMessage(), "hello world"); + assertTrue(ex.getCause() instanceof NullPointerException); + } + + public void testAlreadyExpiredException() throws IOException { + AlreadyExpiredException alreadyExpiredException = serialize(new AlreadyExpiredException("index", "type", "id", 1, 2, 3)); + assertEquals("index", alreadyExpiredException.index()); + assertEquals("type", alreadyExpiredException.type()); + assertEquals("id", alreadyExpiredException.id()); + assertEquals(2, alreadyExpiredException.ttl()); + assertEquals(1, alreadyExpiredException.timestamp()); + assertEquals(3, alreadyExpiredException.now()); + + alreadyExpiredException = serialize(new AlreadyExpiredException(null, null, null, -1, -2, -3)); + assertNull(alreadyExpiredException.index()); + assertNull(alreadyExpiredException.type()); + assertNull(alreadyExpiredException.id()); + assertEquals(-2, alreadyExpiredException.ttl()); + assertEquals(-1, alreadyExpiredException.timestamp()); + assertEquals(-3, alreadyExpiredException.now()); + } + + public void testCreateFailedEngineException() throws IOException { + CreateFailedEngineException ex = serialize(new CreateFailedEngineException(new ShardId("idx", 2), "type", "id", null)); + assertEquals(ex.shardId(), new ShardId("idx", 2)); + assertEquals("type", ex.type()); + assertEquals("id", ex.id()); + assertNull(ex.getCause()); + + ex = serialize(new CreateFailedEngineException(null, "type", "id", new NullPointerException())); + assertNull(ex.shardId()); + assertEquals("type", ex.type()); + assertEquals("id", ex.id()); + assertTrue(ex.getCause() instanceof NullPointerException); + } + + public void testMergeMappingException() throws IOException { + MergeMappingException ex = serialize(new MergeMappingException(new String[] {"one", "two"})); + assertArrayEquals(ex.failures(), new String[]{"one", "two"}); + } + + public void testActionNotFoundTransportException() throws IOException { + ActionNotFoundTransportException ex = serialize(new ActionNotFoundTransportException("AACCCTION")); + assertEquals("AACCCTION", ex.action()); + assertEquals("No handler for action [AACCCTION]", ex.getMessage()); + } + + public void testSnapshotException() throws IOException { + SnapshotException ex = serialize(new SnapshotException(new SnapshotId("repo", "snap"), "no such snapshot", new NullPointerException())); + assertEquals(ex.snapshot(), new SnapshotId("repo", "snap")); + assertEquals(ex.getMessage(), "[repo:snap] no such snapshot"); + assertTrue(ex.getCause() instanceof NullPointerException); + + ex = serialize(new SnapshotException(null, "no such snapshot", new NullPointerException())); + assertEquals(ex.snapshot(), null); + assertEquals(ex.getMessage(), "[_na] no such snapshot"); + assertTrue(ex.getCause() instanceof NullPointerException); + } + + public void testRecoverFilesRecoveryException() throws IOException { + ShardId id = new ShardId("foo", 1); + ByteSizeValue bytes = new ByteSizeValue(randomIntBetween(0, 10000)); + RecoverFilesRecoveryException ex = serialize(new RecoverFilesRecoveryException(id, 10, bytes, null)); + assertEquals(ex.shardId(), id); + assertEquals(ex.numberOfFiles(), 10); + assertEquals(ex.totalFilesSize(), bytes); + assertEquals(ex.getMessage(), "Failed to transfer [10] files with total size of [" + bytes + "]"); + assertNull(ex.getCause()); + + ex = serialize(new RecoverFilesRecoveryException(null, 10, bytes, new NullPointerException())); + assertNull(ex.shardId()); + assertEquals(ex.numberOfFiles(), 10); + assertEquals(ex.totalFilesSize(), bytes); + assertEquals(ex.getMessage(), "Failed to transfer [10] files with total size of [" + bytes + "]"); + assertTrue(ex.getCause() instanceof NullPointerException); + } + + public void testIndexTemplateAlreadyExistsException() throws IOException { + IndexTemplateAlreadyExistsException ex = serialize(new IndexTemplateAlreadyExistsException("the dude abides!")); + assertEquals("the dude abides!", ex.name()); + assertEquals("index_template [the dude abides!] already exists", ex.getMessage()); + + ex = serialize(new IndexTemplateAlreadyExistsException((String)null)); + assertNull(ex.name()); + assertEquals("index_template [null] already exists", ex.getMessage()); + } + + public void testBatchOperationException() throws IOException { + ShardId id = new ShardId("foo", 1); + TranslogRecoveryPerformer.BatchOperationException ex = serialize(new TranslogRecoveryPerformer.BatchOperationException(id, "batched the fucker", 666, null)); + assertEquals(ex.shardId(), id); + assertEquals(666, ex.completedOperations()); + assertEquals("batched the fucker", ex.getMessage()); + assertNull(ex.getCause()); + + ex = serialize(new TranslogRecoveryPerformer.BatchOperationException(null, "batched the fucker", -1, new NullPointerException())); + assertNull(ex.shardId()); + assertEquals(-1, ex.completedOperations()); + assertEquals("batched the fucker", ex.getMessage()); + assertTrue(ex.getCause() instanceof NullPointerException); + } + + public void testInvalidIndexTemplateException() throws IOException { + InvalidIndexTemplateException ex = serialize(new InvalidIndexTemplateException("foo", "bar")); + assertEquals(ex.getMessage(), "index_template [foo] invalid, cause [bar]"); + assertEquals(ex.name(), "foo"); + ex = serialize(new InvalidIndexTemplateException(null, "bar")); + assertEquals(ex.getMessage(), "index_template [null] invalid, cause [bar]"); + assertEquals(ex.name(), null); + } + + public void testActionTransportException() throws IOException { + ActionTransportException ex = serialize(new ActionTransportException("name?", new LocalTransportAddress("dead.end:666"), "ACTION BABY!", "message?", null)); + assertEquals("ACTION BABY!", ex.action()); + assertEquals(new LocalTransportAddress("dead.end:666"), ex.address()); + assertEquals("[name?][local[dead.end:666]][ACTION BABY!] message?", ex.getMessage()); + } + + public void testSearchContextMissingException() throws IOException { + long id = randomLong(); + SearchContextMissingException ex = serialize(new SearchContextMissingException(id)); + assertEquals(id, ex.id()); + } + + public void testPercolateException() throws IOException { + ShardId id = new ShardId("foo", 1); + PercolateException ex = serialize(new PercolateException(id, "percolate my ass", null)); + assertEquals(id, ex.getShardId()); + assertEquals("percolate my ass", ex.getMessage()); + assertNull(ex.getCause()); + + ex = serialize(new PercolateException(id, "percolate my ass", new NullPointerException())); + assertEquals(id, ex.getShardId()); + assertEquals("percolate my ass", ex.getMessage()); + assertTrue(ex.getCause() instanceof NullPointerException); + } + + public void testRoutingValidationException() throws IOException { + RoutingTableValidation validation = new RoutingTableValidation(); + validation.addIndexFailure("foo", "bar"); + RoutingValidationException ex = serialize(new RoutingValidationException(validation)); + assertEquals("[Index [foo]: bar]", ex.getMessage()); + assertEquals(validation.toString(), ex.validation().toString()); + } + + public void testCircuitBreakingException() throws IOException { + CircuitBreakingException ex = serialize(new CircuitBreakingException("I hate to say I told you so...", 0, 100)); + assertEquals("I hate to say I told you so...", ex.getMessage()); + assertEquals(100, ex.getByteLimit()); + assertEquals(0, ex.getBytesWanted()); + } + + public void testTimestampParsingException() throws IOException { + TimestampParsingException ex = serialize(new TimestampParsingException("TIMESTAMP", null)); + assertEquals("failed to parse timestamp [TIMESTAMP]", ex.getMessage()); + assertEquals("TIMESTAMP", ex.timestamp()); + } + + public void testIndexFailedEngineException() throws IOException { + ShardId id = new ShardId("foo", 1); + IndexFailedEngineException ex = serialize(new IndexFailedEngineException(id, "type", "id", null)); + assertEquals(ex.shardId(), new ShardId("foo", 1)); + assertEquals("type", ex.type()); + assertEquals("id", ex.id()); + assertNull(ex.getCause()); + + ex = serialize(new IndexFailedEngineException(null, "type", "id", new NullPointerException())); + assertNull(ex.shardId()); + assertEquals("type", ex.type()); + assertEquals("id", ex.id()); + assertTrue(ex.getCause() instanceof NullPointerException); + } + + public void testAliasesMissingException() throws IOException { + AliasesMissingException ex = serialize(new AliasesMissingException("one", "two", "three")); + assertEquals("aliases [one, two, three] missing", ex.getMessage()); + assertArrayEquals(new String[]{"one", "two", "three"}, ex.names()); + } + + public void testSearchParseException() throws IOException { + SearchContext ctx = new TestSearchContext(); + SearchParseException ex = serialize(new SearchParseException(ctx, "foo", new XContentLocation(66, 666))); + assertEquals("foo", ex.getMessage()); + assertEquals(66, ex.getLineNumber()); + assertEquals(666, ex.getColumnNumber()); + assertEquals(ctx.shardTarget(), ex.shard()); + } + + public void testIllegalIndexShardStateException()throws IOException { + ShardId id = new ShardId("foo", 1); + IndexShardState state = randomFrom(IndexShardState.values()); + IllegalIndexShardStateException ex = serialize(new IllegalIndexShardStateException(id, state, "come back later buddy")); + assertEquals(id, ex.shardId()); + assertEquals("CurrentState[" + state.name() + "] come back later buddy", ex.getMessage()); + assertEquals(state, ex.currentState()); + } + + public void testConnectTransportException() throws IOException { + DiscoveryNode node = new DiscoveryNode("thenode", new LocalTransportAddress("dead.end:666"), Version.CURRENT); + ConnectTransportException ex = serialize(new ConnectTransportException(node, "msg", "action", null)); + assertEquals("[][local[dead.end:666]][action] msg", ex.getMessage()); + assertEquals(node, ex.node()); + assertEquals("action", ex.action()); + assertNull(ex.getCause()); + + ex = serialize(new ConnectTransportException(node, "msg", "action", new NullPointerException())); + assertEquals("[][local[dead.end:666]][action] msg", ex.getMessage()); + assertEquals(node, ex.node()); + assertEquals("action", ex.action()); + assertTrue(ex.getCause() instanceof NullPointerException); + } + + public void testSearchPhaseExecutionException() throws IOException { + ShardSearchFailure[] empty = new ShardSearchFailure[0]; + SearchPhaseExecutionException ex = serialize(new SearchPhaseExecutionException("boom", "baam", new NullPointerException(), empty)); + assertEquals("boom", ex.getPhaseName()); + assertEquals("baam", ex.getMessage()); + assertTrue(ex.getCause() instanceof NullPointerException); + assertEquals(empty.length, ex.shardFailures().length); + ShardSearchFailure[] one = new ShardSearchFailure[] { + new ShardSearchFailure(new IllegalArgumentException("nono!")) + }; + + ex = serialize(new SearchPhaseExecutionException("boom", "baam", new NullPointerException(), one)); + assertEquals("boom", ex.getPhaseName()); + assertEquals("baam", ex.getMessage()); + assertTrue(ex.getCause() instanceof NullPointerException); + assertEquals(one.length, ex.shardFailures().length); + assertTrue(ex.shardFailures()[0].getCause() instanceof IllegalArgumentException); + } + + public void testRoutingMissingException() throws IOException { + RoutingMissingException ex = serialize(new RoutingMissingException("idx", "type", "id")); + assertEquals("idx", ex.index()); + assertEquals("type", ex.type()); + assertEquals("id", ex.id()); + assertEquals("routing is required for [idx]/[type]/[id]", ex.getMessage()); + } + + public void testRepositoryException() throws IOException { + RepositoryException ex = serialize(new RepositoryException("repo", "msg")); + assertEquals("repo", ex.repository()); + assertEquals("[repo] msg", ex.getMessage()); + + ex = serialize(new RepositoryException(null, "msg")); + assertNull(ex.repository()); + assertEquals("[_na] msg", ex.getMessage()); + } + + public void testIndexWarmerMissingException() throws IOException { + IndexWarmerMissingException ex = serialize(new IndexWarmerMissingException("w1", "w2")); + assertEquals("index_warmer [w1, w2] missing", ex.getMessage()); + assertArrayEquals(new String[]{"w1", "w2"}, ex.names()); + } + + public void testIndexTemplateMissingException() throws IOException { + IndexTemplateMissingException ex = serialize(new IndexTemplateMissingException("name")); + assertEquals("index_template [name] missing", ex.getMessage()); + assertEquals("name", ex.name()); + + ex = serialize(new IndexTemplateMissingException((String)null)); + assertEquals("index_template [null] missing", ex.getMessage()); + assertNull(ex.name()); + } + + public void testIndexException() throws IOException { + IndexException ex = serialize(new IndexException(new Index("foo"), "blub")); + assertEquals("blub", ex.getMessage()); + assertEquals(new Index("foo"), ex.index()); + + ex = serialize(new IndexException(null, "blub")); + assertEquals("blub", ex.getMessage()); + assertNull(ex.index()); + } + + public void testRecoveryEngineException() throws IOException { + ShardId id = new ShardId("foo", 1); + RecoveryEngineException ex = serialize(new RecoveryEngineException(id, 10, "total failure", new NullPointerException())); + assertEquals(id, ex.shardId()); + assertEquals("Phase[10] total failure", ex.getMessage()); + assertEquals(10, ex.phase()); + ex = serialize(new RecoveryEngineException(null, -1, "total failure", new NullPointerException())); + assertNull(ex.shardId()); + assertEquals(-1, ex.phase()); + assertTrue(ex.getCause() instanceof NullPointerException); + } + + public void testFailedNodeException() throws IOException { + FailedNodeException ex = serialize(new FailedNodeException("the node", "the message", null)); + assertEquals("the node", ex.nodeId()); + assertEquals("the message", ex.getMessage()); + } + + public void testClusterBlockException() throws IOException { + ClusterBlockException ex = serialize(new ClusterBlockException(ImmutableSet.of(DiscoverySettings.NO_MASTER_BLOCK_WRITES))); + assertEquals("blocked by: [SERVICE_UNAVAILABLE/2/no master];", ex.getMessage()); + assertTrue(ex.blocks().contains(DiscoverySettings.NO_MASTER_BLOCK_WRITES)); + assertEquals(1, ex.blocks().size()); + } + + public void testIndexShardException() throws IOException { + ShardId id = new ShardId("foo", 1); + IndexShardException ex = serialize(new IndexShardException(id, "boom", new NullPointerException())); + assertEquals(id, ex.shardId()); + assertEquals("boom", ex.getMessage()); + assertEquals(new Index("foo"), ex.index()); + assertTrue(ex.getCause() instanceof NullPointerException); + ex = serialize(new IndexShardException(null, "boom", new NullPointerException())); + assertEquals("boom", ex.getMessage()); + assertNull(ex.index()); + assertNull(ex.shardId()); + } +} From 4e2621ca2143262a8b8849d7b29f4e8c50f3aaf8 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 30 Jun 2015 10:00:10 +0200 Subject: [PATCH 13/19] Cleanup non-serializable code --- .../elasticsearch/ElasticsearchException.java | 19 +++++-- .../NotSerializableExceptionWrapper.java | 54 +++++++++++++++++++ .../common/io/stream/StreamInput.java | 29 ---------- .../common/io/stream/StreamOutput.java | 4 +- .../ExceptionSerializationTests.java | 26 +++++++-- 5 files changed, 92 insertions(+), 40 deletions(-) create mode 100644 core/src/main/java/org/elasticsearch/common/io/stream/NotSerializableExceptionWrapper.java diff --git a/core/src/main/java/org/elasticsearch/ElasticsearchException.java b/core/src/main/java/org/elasticsearch/ElasticsearchException.java index 362ec91d533..16b6df065a8 100644 --- a/core/src/main/java/org/elasticsearch/ElasticsearchException.java +++ b/core/src/main/java/org/elasticsearch/ElasticsearchException.java @@ -26,6 +26,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.HasRestHeaders; @@ -42,7 +43,7 @@ import java.util.*; public class ElasticsearchException extends RuntimeException implements ToXContent { public static final String REST_EXCEPTION_SKIP_CAUSE = "rest.exception.skip_cause"; - static final Map> MAPPING; + private static final Map> MAPPING; /** * Construct a ElasticsearchException with the specified detail message. @@ -177,6 +178,17 @@ public class ElasticsearchException extends RuntimeException implements ToXConte } } + /** + * Retruns true iff the given name is a registered for an exception to be read. + */ + static boolean isRegistered(String name) { + return MAPPING.containsKey(name); + } + + static Set getRegisteredKeys() { // for testing + return MAPPING.keySet(); + } + /** * A base class for exceptions that should carry rest headers */ @@ -533,10 +545,9 @@ public class ElasticsearchException extends RuntimeException implements ToXConte org.elasticsearch.action.PrimaryMissingActionException.class, org.elasticsearch.index.engine.CreateFailedEngineException.class, org.elasticsearch.index.shard.IllegalIndexShardStateException.class, - org.elasticsearch.common.io.stream.StreamInput.NamedException.class + NotSerializableExceptionWrapper.class }; - Map> mapping = new HashMap<>(); - + Map> mapping = new HashMap<>(exceptions.length); for (Class e : exceptions) { String name = e.getName(); try { diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/NotSerializableExceptionWrapper.java b/core/src/main/java/org/elasticsearch/common/io/stream/NotSerializableExceptionWrapper.java new file mode 100644 index 00000000000..c77233246ed --- /dev/null +++ b/core/src/main/java/org/elasticsearch/common/io/stream/NotSerializableExceptionWrapper.java @@ -0,0 +1,54 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.common.io.stream; + +import org.elasticsearch.ElasticsearchException; + +import java.io.IOException; + +/** + * This exception can be used to wrap a given, not serializable exception + * to serialize via {@link StreamOutput#writeThrowable(Throwable)} + */ +public final class NotSerializableExceptionWrapper extends ElasticsearchException { + + private final String name; + + public NotSerializableExceptionWrapper(Throwable other) { + super(other.getMessage(), other.getCause()); + this.name = ElasticsearchException.getExceptionName(other); + } + + public NotSerializableExceptionWrapper(StreamInput in) throws IOException { + super(in); + name = in.readString(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeString(name); + } + + @Override + protected String getExceptionName() { + return name; + } +} diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java index f2d5416a6d0..e8e3f6f6d20 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java @@ -546,33 +546,4 @@ public abstract class StreamInput extends InputStream { return new InputStreamStreamInput(new ByteArrayInputStream(bytes, offset, length)); } - public static class NamedException extends ElasticsearchException { - - private final String name; - - public NamedException(String name, String msg, Throwable cause) { - super(msg, cause); - if (name == null) { - throw new IllegalArgumentException("name must not be null"); - } - this.name = name; - } - - public NamedException(StreamInput in) throws IOException { - super(in); - name = in.readString(); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeString(name); - } - - @Override - protected String getExceptionName() { - return Strings.toUnderscoreCase(name); - } - } - } diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java index 57a0585526d..da6ab25e65f 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java @@ -26,7 +26,6 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; -import org.elasticsearch.bootstrap.Elasticsearch; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.text.Text; @@ -34,7 +33,6 @@ import org.joda.time.ReadableInstant; import java.io.EOFException; import java.io.IOException; -import java.io.ObjectOutputStream; import java.io.OutputStream; import java.util.Date; import java.util.LinkedHashMap; @@ -478,7 +476,7 @@ public abstract class StreamOutput extends OutputStream { if (throwable instanceof ElasticsearchException) { ex = (ElasticsearchException) throwable; } else { - ex = new StreamInput.NamedException(ElasticsearchException.getExceptionName(throwable), throwable.getMessage(), throwable.getCause()); + ex = new NotSerializableExceptionWrapper(throwable); } writeVInt(0); writeString(ex.getClass().getName()); diff --git a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java index 8c0088a78cf..fa25846c12e 100644 --- a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java +++ b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java @@ -36,7 +36,7 @@ import org.elasticsearch.common.io.stream.*; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.common.xcontent.XContentLocation; +import org.elasticsearch.common.xcontent.*; import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.index.AlreadyExpiredException; import org.elasticsearch.index.Index; @@ -115,9 +115,9 @@ public class ExceptionSerializationTests extends ElasticsearchTestCase { Class clazz = loadClass(filename); if (ignore.contains(clazz) == false) { if (Modifier.isAbstract(clazz.getModifiers()) == false && Modifier.isInterface(clazz.getModifiers()) == false && isEsException(clazz)) { - if (ElasticsearchException.MAPPING.containsKey(clazz.getName()) == false && ElasticsearchException.class.equals(clazz.getEnclosingClass()) == false) { + if (ElasticsearchException.isRegistered(clazz.getName()) == false && ElasticsearchException.class.equals(clazz.getEnclosingClass()) == false) { notRegistered.add(clazz); - } else if (ElasticsearchException.MAPPING.containsKey(clazz.getName())) { + } else if (ElasticsearchException.isRegistered(clazz.getName())) { registered.add(clazz.getName()); try { if (clazz.getDeclaredMethod("writeTo", StreamOutput.class) != null) { @@ -169,7 +169,7 @@ public class ExceptionSerializationTests extends ElasticsearchTestCase { assertTrue(notRegistered.remove(TestException.class)); assertTrue("Classes subclassing ElasticsearchException must be registered \n" + notRegistered.toString(), notRegistered.isEmpty()); - assertTrue(registered.removeAll(ElasticsearchException.MAPPING.keySet())); // check + assertTrue(registered.removeAll(ElasticsearchException.getRegisteredKeys())); // check assertEquals(registered.toString(), 0, registered.size()); } @@ -535,4 +535,22 @@ public class ExceptionSerializationTests extends ElasticsearchTestCase { assertNull(ex.index()); assertNull(ex.shardId()); } + private String toXContent(ToXContent x) { + try { + XContentBuilder builder = XContentFactory.jsonBuilder(); + builder.startObject(); + x.toXContent(builder, ToXContent.EMPTY_PARAMS); + builder.endObject(); + return builder.string(); + } catch (IOException e) { + return "{ \"error\" : \"" + e.getMessage() + "\"}"; + } + } + + public void testNotSerializableExceptionWrapper() throws IOException { + NotSerializableExceptionWrapper ex = serialize(new NotSerializableExceptionWrapper(new NullPointerException())); + assertEquals("{\"type\":\"null_pointer_exception\",\"reason\":null}", toXContent(ex)); + ex = serialize(new NotSerializableExceptionWrapper(new IllegalArgumentException("nono!"))); + assertEquals("{\"type\":\"illegal_argument_exception\",\"reason\":\"nono!\"}", toXContent(ex)); + } } From 325cc6bc615e7e2a90343323464362db59847890 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 30 Jun 2015 10:06:35 +0200 Subject: [PATCH 14/19] serialize as not-serializable if exception is not registered --- .../main/java/org/elasticsearch/ElasticsearchException.java | 2 +- .../java/org/elasticsearch/common/io/stream/StreamOutput.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/ElasticsearchException.java b/core/src/main/java/org/elasticsearch/ElasticsearchException.java index 16b6df065a8..978ac1185a9 100644 --- a/core/src/main/java/org/elasticsearch/ElasticsearchException.java +++ b/core/src/main/java/org/elasticsearch/ElasticsearchException.java @@ -181,7 +181,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte /** * Retruns true iff the given name is a registered for an exception to be read. */ - static boolean isRegistered(String name) { + public static boolean isRegistered(String name) { return MAPPING.containsKey(name); } diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java index da6ab25e65f..fc4726d6c28 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java @@ -473,7 +473,8 @@ public abstract class StreamOutput extends OutputStream { writeVInt(9); } else { ElasticsearchException ex; - if (throwable instanceof ElasticsearchException) { + final String name = throwable.getClass().getName(); + if (throwable instanceof ElasticsearchException && ElasticsearchException.isRegistered(name)) { ex = (ElasticsearchException) throwable; } else { ex = new NotSerializableExceptionWrapper(throwable); From 0148c462e0baa9133e323afe578d7d057a426337 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 30 Jun 2015 10:12:43 +0200 Subject: [PATCH 15/19] remove leftover ObjectOutputStream references --- .../java/org/elasticsearch/common/Base64.java | 91 ------------------- 1 file changed, 91 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/Base64.java b/core/src/main/java/org/elasticsearch/common/Base64.java index c1b63d09e4f..f14885892e1 100644 --- a/core/src/main/java/org/elasticsearch/common/Base64.java +++ b/core/src/main/java/org/elasticsearch/common/Base64.java @@ -1224,97 +1224,6 @@ public class Base64 { } // end decode - /** - * Attempts to decode Base64 data and deserialize a Java - * Object within. Returns null if there was an error. - * - * @param encodedObject The Base64 data to decode - * @return The decoded and deserialized object - * @throws NullPointerException if encodedObject is null - * @throws java.io.IOException if there is a general error - * @throws ClassNotFoundException if the decoded object is of a - * class that cannot be found by the JVM - * @since 1.5 - */ - public static Object decodeToObject(String encodedObject) - throws java.io.IOException, java.lang.ClassNotFoundException { - return decodeToObject(encodedObject, NO_OPTIONS, null); - } - - - /** - * Attempts to decode Base64 data and deserialize a Java - * Object within. Returns null if there was an error. - * If loader is not null, it will be the class loader - * used when deserializing. - * - * @param encodedObject The Base64 data to decode - * @param options Various parameters related to decoding - * @param loader Optional class loader to use in deserializing classes. - * @return The decoded and deserialized object - * @throws NullPointerException if encodedObject is null - * @throws java.io.IOException if there is a general error - * @throws ClassNotFoundException if the decoded object is of a - * class that cannot be found by the JVM - * @since 2.3.4 - */ - public static Object decodeToObject( - String encodedObject, int options, final ClassLoader loader) - throws java.io.IOException, java.lang.ClassNotFoundException { - - // Decode and gunzip if necessary - byte[] objBytes = decode(encodedObject, options); - - java.io.ByteArrayInputStream bais = null; - java.io.ObjectInputStream ois = null; - Object obj = null; - - try { - bais = new java.io.ByteArrayInputStream(objBytes); - - // If no custom class loader is provided, use Java's builtin OIS. - if (loader == null) { - ois = new java.io.ObjectInputStream(bais); - } // end if: no loader provided - - // Else make a customized object input stream that uses - // the provided class loader. - else { - ois = new java.io.ObjectInputStream(bais) { - @Override - public Class resolveClass(java.io.ObjectStreamClass streamClass) - throws java.io.IOException, ClassNotFoundException { - Class c = Class.forName(streamClass.getName(), false, loader); - if (c == null) { - return super.resolveClass(streamClass); - } else { - return c; // Class loader knows of this class. - } // end else: not null - } // end resolveClass - }; // end ois - } // end else: no custom class loader - - obj = ois.readObject(); - } // end try - catch (java.io.IOException e) { - throw e; // Catch and throw in order to execute finally{} - } // end catch - catch (java.lang.ClassNotFoundException e) { - throw e; // Catch and throw in order to execute finally{} - } // end catch - finally { - try { - bais.close(); - } catch (Exception e) { - } - try { - ois.close(); - } catch (Exception e) { - } - } // end finally - - return obj; - } // end decodeObject /* ******** I N N E R C L A S S I N P U T S T R E A M ******** */ From 971ac0475e216e4584dafdf6888d213b94ac44b1 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 30 Jun 2015 10:44:30 +0200 Subject: [PATCH 16/19] add IOOB to supported exceptions --- .../org/elasticsearch/common/io/stream/StreamInput.java | 8 ++++++++ .../org/elasticsearch/common/io/stream/StreamOutput.java | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java index e8e3f6f6d20..1affc8bd0d9 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java @@ -524,6 +524,14 @@ public abstract class StreamInput extends InputStream { return (T) readStackTrace(new EOFException(eofMessage), this); case 9: return (T) readStackTrace(new SecurityException(readOptionalString(), readThrowable()), this); + case 10: + final String sidxMessage = readOptionalString(); + readThrowable(); + return (T) readStackTrace(new StringIndexOutOfBoundsException(sidxMessage), this); + case 11: + final String aidxMessage = readOptionalString(); + readThrowable(); + return (T) readStackTrace(new ArrayIndexOutOfBoundsException(aidxMessage), this); default: assert false : "no such exception for id: " + key; } diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java index fc4726d6c28..75e81f7d6ec 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java @@ -471,6 +471,10 @@ public abstract class StreamOutput extends OutputStream { writeVInt(8); } else if (throwable instanceof SecurityException) { writeVInt(9); + } else if (throwable instanceof StringIndexOutOfBoundsException) { + writeVInt(10); + } else if (throwable instanceof ArrayIndexOutOfBoundsException) { + writeVInt(11); } else { ElasticsearchException ex; final String name = throwable.getClass().getName(); From 6ee9a3d5f2938dee8bd73fd7c4c1dd6b89b0f311 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 30 Jun 2015 13:25:50 +0200 Subject: [PATCH 17/19] add more essential exceptions --- .../elasticsearch/ElasticsearchException.java | 2 +- .../common/io/stream/StreamInput.java | 47 ++++++++++--------- .../common/io/stream/StreamOutput.java | 35 +++++++++++++- .../ElasticsearchExceptionTests.java | 13 ++++- 4 files changed, 73 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/ElasticsearchException.java b/core/src/main/java/org/elasticsearch/ElasticsearchException.java index 978ac1185a9..cc71126f60f 100644 --- a/core/src/main/java/org/elasticsearch/ElasticsearchException.java +++ b/core/src/main/java/org/elasticsearch/ElasticsearchException.java @@ -557,7 +557,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte } mapping.put(name, constructor); } catch (NoSuchMethodException t) { - throw new RuntimeException("failed to register [" + name + "] ", t); + throw new RuntimeException("failed to register [" + name + "] exception must have a public StreamInput ctor", t); } } diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java index 1affc8bd0d9..214b40d1218 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java @@ -22,6 +22,8 @@ package org.elasticsearch.common.io.stream; import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.IndexFormatTooNewException; import org.apache.lucene.index.IndexFormatTooOldException; +import org.apache.lucene.store.AlreadyClosedException; +import org.apache.lucene.store.LockObtainFailedException; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.CharsRefBuilder; import org.elasticsearch.ElasticsearchException; @@ -36,6 +38,7 @@ import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import java.io.*; +import java.nio.file.NoSuchFileException; import java.util.*; import java.util.regex.Pattern; @@ -499,39 +502,41 @@ public abstract class StreamInput extends InputStream { msg = msg.substring(0, idx); return (T) readStackTrace(new CorruptIndexException(msg, resource, readThrowable()), this); // Lucene 5.3 will have getters for all these case 2: - final String itnMessage = readOptionalString(); - readThrowable(); - return (T) readStackTrace(new IndexFormatTooNewException(itnMessage, -1, -1, -1), this); + return (T) readStackTrace(new IndexFormatTooNewException(readOptionalString(), -1, -1, -1), this); // Lucene 5.3 will have getters for all these case 3: - final String itoMessage = readOptionalString(); - readThrowable(); - return (T) readStackTrace(new IndexFormatTooOldException(itoMessage, -1, -1, -1), this); + return (T) readStackTrace(new IndexFormatTooOldException(readOptionalString(), -1, -1, -1), this); // Lucene 5.3 will have getters for all these case 4: - final String npeMessage = readOptionalString(); - readThrowable(); - return (T) readStackTrace(new NullPointerException(npeMessage), this); + return (T) readStackTrace(new NullPointerException(readOptionalString()), this); case 5: - final String nfeMessage = readOptionalString(); - readThrowable(); - return (T) readStackTrace(new NumberFormatException(nfeMessage), this); + return (T) readStackTrace(new NumberFormatException(readOptionalString()), this); case 6: return (T) readStackTrace(new IllegalArgumentException(readOptionalString(), readThrowable()), this); case 7: return (T) readStackTrace(new IllegalStateException(readOptionalString(), readThrowable()), this); case 8: - final String eofMessage = readOptionalString(); - readThrowable(); - return (T) readStackTrace(new EOFException(eofMessage), this); + return (T) readStackTrace(new EOFException(readOptionalString()), this); case 9: return (T) readStackTrace(new SecurityException(readOptionalString(), readThrowable()), this); case 10: - final String sidxMessage = readOptionalString(); - readThrowable(); - return (T) readStackTrace(new StringIndexOutOfBoundsException(sidxMessage), this); + return (T) readStackTrace(new StringIndexOutOfBoundsException(readOptionalString()), this); case 11: - final String aidxMessage = readOptionalString(); - readThrowable(); - return (T) readStackTrace(new ArrayIndexOutOfBoundsException(aidxMessage), this); + return (T) readStackTrace(new ArrayIndexOutOfBoundsException(readOptionalString()), this); + case 12: + return (T) readStackTrace(new AssertionError(readOptionalString(), readThrowable()), this); + case 13: + return (T) readStackTrace(new FileNotFoundException(readOptionalString()), this); + case 14: + final String file = readOptionalString(); + final String other = readOptionalString(); + final String reason = readOptionalString(); + readOptionalString(); // skip the msg - it's composed from file, other and reason + return (T) readStackTrace(new NoSuchFileException(file, other, reason), this); + case 15: + return (T) readStackTrace(new OutOfMemoryError(readOptionalString()), this); + case 16: + return (T) readStackTrace(new AlreadyClosedException(readOptionalString(), readThrowable()), this); + case 17: + return (T) readStackTrace(new LockObtainFailedException(readOptionalString(), readThrowable()), this); default: assert false : "no such exception for id: " + key; } diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java index 75e81f7d6ec..c22880c28ff 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java @@ -19,9 +19,12 @@ package org.elasticsearch.common.io.stream; +import com.vividsolutions.jts.util.Assert; import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.IndexFormatTooNewException; import org.apache.lucene.index.IndexFormatTooOldException; +import org.apache.lucene.store.AlreadyClosedException; +import org.apache.lucene.store.LockObtainFailedException; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; import org.elasticsearch.ElasticsearchException; @@ -32,8 +35,10 @@ import org.elasticsearch.common.text.Text; import org.joda.time.ReadableInstant; import java.io.EOFException; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.OutputStream; +import java.nio.file.NoSuchFileException; import java.util.Date; import java.util.LinkedHashMap; import java.util.List; @@ -453,28 +458,54 @@ public abstract class StreamOutput extends OutputStream { writeBoolean(false); } else { writeBoolean(true); + boolean writeCause = true; if (throwable instanceof CorruptIndexException) { writeVInt(1); } else if (throwable instanceof IndexFormatTooNewException) { writeVInt(2); + writeCause = false; } else if (throwable instanceof IndexFormatTooOldException) { writeVInt(3); + writeCause = false; } else if (throwable instanceof NullPointerException) { writeVInt(4); + writeCause = false; } else if (throwable instanceof NumberFormatException) { writeVInt(5); + writeCause = false; } else if (throwable instanceof IllegalArgumentException) { writeVInt(6); } else if (throwable instanceof IllegalStateException) { writeVInt(7); } else if (throwable instanceof EOFException) { writeVInt(8); + writeCause = false; } else if (throwable instanceof SecurityException) { writeVInt(9); } else if (throwable instanceof StringIndexOutOfBoundsException) { writeVInt(10); + writeCause = false; } else if (throwable instanceof ArrayIndexOutOfBoundsException) { writeVInt(11); + writeCause = false; + } else if (throwable instanceof AssertionError) { + writeVInt(12); + } else if (throwable instanceof FileNotFoundException) { + writeVInt(13); + writeCause = false; + } else if (throwable instanceof NoSuchFileException) { + writeVInt(14); + writeOptionalString(((NoSuchFileException) throwable).getFile()); + writeOptionalString(((NoSuchFileException) throwable).getOtherFile()); + writeOptionalString(((NoSuchFileException) throwable).getReason()); + writeCause = false; + } else if (throwable instanceof OutOfMemoryError) { + writeVInt(15); + writeCause = false; + } else if (throwable instanceof AlreadyClosedException) { + writeVInt(16); + } else if (throwable instanceof LockObtainFailedException) { + writeVInt(17); } else { ElasticsearchException ex; final String name = throwable.getClass().getName(); @@ -490,7 +521,9 @@ public abstract class StreamOutput extends OutputStream { } writeOptionalString(throwable.getMessage()); - writeThrowable(throwable.getCause()); + if (writeCause) { + writeThrowable(throwable.getCause()); + } ElasticsearchException.writeStackTraces(throwable, this); } } diff --git a/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java b/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java index 5a30cb05b04..cb3f60285e9 100644 --- a/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java +++ b/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java @@ -22,6 +22,8 @@ package org.elasticsearch; import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.IndexFormatTooNewException; import org.apache.lucene.index.IndexFormatTooOldException; +import org.apache.lucene.store.AlreadyClosedException; +import org.apache.lucene.store.LockObtainFailedException; import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.elasticsearch.action.search.ShardSearchFailure; import org.elasticsearch.common.io.stream.BytesStreamOutput; @@ -43,6 +45,7 @@ import org.junit.Test; import java.io.EOFException; import java.io.FileNotFoundException; import java.io.IOException; +import java.nio.file.NoSuchFileException; import static org.hamcrest.Matchers.equalTo; @@ -264,6 +267,14 @@ public class ElasticsearchExceptionTests extends ElasticsearchTestCase { new CorruptIndexException("baaaam", "this is my resource"), new IndexFormatTooNewException("tooo new", 1, 1, 1), new IndexFormatTooOldException("tooo new", 1, 1, 1), + new ArrayIndexOutOfBoundsException("booom"), + new StringIndexOutOfBoundsException("booom"), + new FileNotFoundException("booom"), + new NoSuchFileException("booom"), + new AssertionError("booom", new NullPointerException()), + new OutOfMemoryError("no memory left"), + new AlreadyClosedException("closed!!", new NullPointerException()), + new LockObtainFailedException("can't lock directory", new NullPointerException()), new Throwable("this exception is unknown", new QueryParsingException(new Index("foo"), 1, 2, "foobar", null) ), // somethin unknown }; for (Throwable t : causes) { @@ -277,7 +288,7 @@ public class ElasticsearchExceptionTests extends ElasticsearchTestCase { // these don't work yet - missing ctors assertNotEquals(e.getCause().getMessage(), ex.getCause().getMessage()); } else { - assertEquals(e.getCause().getMessage(), ex.getCause().getMessage()); + assertEquals(ex.getCause().getClass().getName(), e.getCause().getMessage(), ex.getCause().getMessage()); } assertEquals(e.getCause().getClass(), e.getCause().getClass()); assertArrayEquals(e.getStackTrace(), ex.getStackTrace()); From 0ac8c1bc55886010d616ddf97cdde1d60f8d22f0 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 30 Jun 2015 14:43:42 +0200 Subject: [PATCH 18/19] Carry on stacktrace and suppressed exceptions if exception is not serializable --- .../NotSerializableExceptionWrapper.java | 9 +++++- .../common/io/stream/StreamInput.java | 2 ++ .../ElasticsearchExceptionTests.java | 7 +++-- .../ExceptionSerializationTests.java | 31 +++++++++++++++++-- .../hamcrest/ElasticsearchAssertions.java | 27 ++++++++++++++++ 5 files changed, 70 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/NotSerializableExceptionWrapper.java b/core/src/main/java/org/elasticsearch/common/io/stream/NotSerializableExceptionWrapper.java index c77233246ed..7fc63827757 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/NotSerializableExceptionWrapper.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/NotSerializableExceptionWrapper.java @@ -25,7 +25,10 @@ import java.io.IOException; /** * This exception can be used to wrap a given, not serializable exception - * to serialize via {@link StreamOutput#writeThrowable(Throwable)} + * to serialize via {@link StreamOutput#writeThrowable(Throwable)}. + * This class will perserve the stacktrace as well as the suppressed exceptions of + * the throwable it was created with instead of it's own. The stacktrace has no indication + * of where this exception was created. */ public final class NotSerializableExceptionWrapper extends ElasticsearchException { @@ -34,6 +37,10 @@ public final class NotSerializableExceptionWrapper extends ElasticsearchExceptio public NotSerializableExceptionWrapper(Throwable other) { super(other.getMessage(), other.getCause()); this.name = ElasticsearchException.getExceptionName(other); + setStackTrace(other.getStackTrace()); + for (Throwable otherSuppressed : other.getSuppressed()) { + addSuppressed(otherSuppressed); + } } public NotSerializableExceptionWrapper(StreamInput in) throws IOException { diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java index 214b40d1218..8ad880a1c0d 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java @@ -19,6 +19,8 @@ package org.elasticsearch.common.io.stream; +import com.fasterxml.jackson.core.JsonLocation; +import com.fasterxml.jackson.core.JsonParseException; import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.IndexFormatTooNewException; import org.apache.lucene.index.IndexFormatTooOldException; diff --git a/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java b/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java index cb3f60285e9..acf490b4ce4 100644 --- a/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java +++ b/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java @@ -39,6 +39,8 @@ import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.test.ElasticsearchTestCase; +import org.elasticsearch.test.VersionUtils; +import org.elasticsearch.test.hamcrest.ElasticsearchAssertions; import org.elasticsearch.transport.RemoteTransportException; import org.junit.Test; @@ -293,9 +295,10 @@ public class ElasticsearchExceptionTests extends ElasticsearchTestCase { assertEquals(e.getCause().getClass(), e.getCause().getClass()); assertArrayEquals(e.getStackTrace(), ex.getStackTrace()); assertTrue(e.getStackTrace().length > 1); + ElasticsearchAssertions.assertVersionSerializable(VersionUtils.randomVersion(getRandom()), t); + ElasticsearchAssertions.assertVersionSerializable(VersionUtils.randomVersion(getRandom()), ex); + ElasticsearchAssertions.assertVersionSerializable(VersionUtils.randomVersion(getRandom()), e); } - - } } \ No newline at end of file diff --git a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java index fa25846c12e..97efcf64d0b 100644 --- a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java +++ b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java @@ -18,14 +18,16 @@ */ package org.elasticsearch; +import com.fasterxml.jackson.core.JsonLocation; +import com.fasterxml.jackson.core.JsonParseException; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; +import org.codehaus.groovy.runtime.typehandling.GroovyCastException; import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.RoutingMissingException; import org.elasticsearch.action.TimestampParsingException; import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.elasticsearch.action.search.ShardSearchFailure; -import org.elasticsearch.cluster.block.ClusterBlock; import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.metadata.SnapshotId; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -33,7 +35,6 @@ import org.elasticsearch.cluster.routing.*; import org.elasticsearch.common.breaker.CircuitBreakingException; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.stream.*; -import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.LocalTransportAddress; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.xcontent.*; @@ -63,6 +64,8 @@ import org.elasticsearch.search.warmer.IndexWarmerMissingException; import org.elasticsearch.snapshots.SnapshotException; import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.test.TestSearchContext; +import org.elasticsearch.test.VersionUtils; +import org.elasticsearch.test.hamcrest.ElasticsearchAssertions; import org.elasticsearch.transport.ActionNotFoundTransportException; import org.elasticsearch.transport.ActionTransportException; import org.elasticsearch.transport.ConnectTransportException; @@ -179,7 +182,8 @@ public class ExceptionSerializationTests extends ElasticsearchTestCase { } } - private T serialize(T exception) throws IOException { + private T serialize(T exception) throws IOException { + ElasticsearchAssertions.assertVersionSerializable(VersionUtils.randomVersion(random()), exception); BytesStreamOutput out = new BytesStreamOutput(); out.writeThrowable(exception); StreamInput in = StreamInput.wrap(out.bytes()); @@ -552,5 +556,26 @@ public class ExceptionSerializationTests extends ElasticsearchTestCase { assertEquals("{\"type\":\"null_pointer_exception\",\"reason\":null}", toXContent(ex)); ex = serialize(new NotSerializableExceptionWrapper(new IllegalArgumentException("nono!"))); assertEquals("{\"type\":\"illegal_argument_exception\",\"reason\":\"nono!\"}", toXContent(ex)); + + Throwable[] unknowns = new Throwable[] { + new JsonParseException("foobar", new JsonLocation(new Object(), 1,2,3,4)), + new GroovyCastException("boom boom boom"), + new IOException("booom") + }; + for (Throwable t : unknowns) { + if (randomBoolean()) { + t.addSuppressed(new IOException("suppressed")); + t.addSuppressed(new NullPointerException()); + } + Throwable deserialized = serialize(t); + assertTrue(deserialized instanceof NotSerializableExceptionWrapper); + assertArrayEquals(t.getStackTrace(), deserialized.getStackTrace()); + assertEquals(t.getSuppressed().length, deserialized.getSuppressed().length); + if (t.getSuppressed().length > 0) { + assertTrue(deserialized.getSuppressed()[0] instanceof NotSerializableExceptionWrapper); + assertArrayEquals(t.getSuppressed()[0].getStackTrace(), deserialized.getSuppressed()[0].getStackTrace()); + assertTrue(deserialized.getSuppressed()[1] instanceof NullPointerException); + } + } } } diff --git a/core/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java b/core/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java index 819c1d5ab1d..f9430edd6b9 100644 --- a/core/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java +++ b/core/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java @@ -60,6 +60,7 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.search.SearchHit; @@ -650,6 +651,32 @@ public class ElasticsearchAssertions { } + public static void assertVersionSerializable(Version version, final Throwable t) { + ElasticsearchAssertions.assertVersionSerializable(version, new ThrowableWrapper(t)); + } + + private static final class ThrowableWrapper implements Streamable { + Throwable throwable; + public ThrowableWrapper(Throwable t) { + throwable = t; + } + + public ThrowableWrapper() { + throwable = null; + } + + @Override + public void readFrom(StreamInput in) throws IOException { + throwable = in.readThrowable(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeThrowable(throwable); + } + } + + private static Streamable tryCreateNewInstance(Streamable streamable) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { try { From bbaf4710cbf056134ec789ed3d6fe7ea2af1a05d Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 30 Jun 2015 15:51:48 +0200 Subject: [PATCH 19/19] FileName is optional in StacktraceElement --- .../main/java/org/elasticsearch/ElasticsearchException.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/ElasticsearchException.java b/core/src/main/java/org/elasticsearch/ElasticsearchException.java index cc71126f60f..0de317582b6 100644 --- a/core/src/main/java/org/elasticsearch/ElasticsearchException.java +++ b/core/src/main/java/org/elasticsearch/ElasticsearchException.java @@ -366,7 +366,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte StackTraceElement[] stackTrace = new StackTraceElement[stackTraceElements]; for (int i = 0; i < stackTraceElements; i++) { final String declaringClasss = in.readString(); - final String fileName = in.readString(); + final String fileName = in.readOptionalString(); final String methodName = in.readString(); final int lineNumber = in.readVInt(); stackTrace[i] = new StackTraceElement(declaringClasss,methodName, fileName, lineNumber); @@ -388,7 +388,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte out.writeVInt(stackTrace.length); for (StackTraceElement element : stackTrace) { out.writeString(element.getClassName()); - out.writeString(element.getFileName()); + out.writeOptionalString(element.getFileName()); out.writeString(element.getMethodName()); out.writeVInt(element.getLineNumber()); }