From cf485f778d258df0c3bb59bee0ab047daf86eaf5 Mon Sep 17 00:00:00 2001 From: Nick Knize Date: Tue, 6 Jun 2023 14:19:47 -0500 Subject: [PATCH] [Refactor] OpenSearchException streamables to a registry (#7646) * [Refactor] OpenSearchException streamables to a registry OpenSearchException uses an enumerator to create a handler for each serializable Exception implementation. The enumerator is to make it easy to store in an immutable map. The problem with this Hack is that it makes it difficult to unwind the tight coupling of StreamInput with the OpenSearchException class. This commit switches from using an enumerator to a registry in the opensearch-core library in order to support serverless and cloud native implementations outside of the server module. This commit also refactors base primitive serialization readers and writers from StreamInput and StreamOutput to BaseStreamInput and BaseStreamOutput, respectively. Signed-off-by: Nicholas Walter Knize * revert Project_Default Signed-off-by: Nicholas Walter Knize --------- Signed-off-by: Nicholas Walter Knize --- .idea/inspectionProfiles/Project_Default.xml | 2 +- .../opensearch/BaseOpenSearchException.java | 98 + .../common/io/stream/BaseStreamInput.java | 324 ++- .../common/io/stream/BaseStreamOutput.java | 133 +- .../core}/common/lease/Releasable.java | 6 +- .../core}/common/lease/Releasables.java | 2 +- .../core}/common/lease/package-info.java | 2 +- .../matrix/stats/MatrixStatsAggregator.java | 2 +- .../bucket/geogrid/GeoGridAggregator.java | 2 +- .../metrics/AbstractGeoBoundsAggregator.java | 2 +- .../aggregations/ParentJoinAggregator.java | 4 +- .../netty4/Netty4MessageChannelHandler.java | 2 +- .../transport/netty4/Netty4Transport.java | 2 +- .../transport/nio/TcpReadWriteHandler.java | 4 +- .../opensearch/index/IndexingPressureIT.java | 2 +- .../index/SegmentReplicationPressureIT.java | 2 +- .../index/ShardIndexingPressureIT.java | 2 +- .../ShardIndexingPressureSettingsIT.java | 2 +- .../replication/SegmentReplicationBaseIT.java | 2 +- .../replication/SegmentReplicationIT.java | 2 +- .../indices/state/ReopenWhileClosingIT.java | 2 +- .../org/opensearch/OpenSearchException.java | 2138 +++++++++-------- ...TransportVerifyShardBeforeCloseAction.java | 2 +- .../TransportVerifyShardIndexBlockAction.java | 2 +- .../query/TransportValidateQueryAction.java | 2 +- .../action/bulk/TransportBulkAction.java | 2 +- .../action/bulk/TransportShardBulkAction.java | 4 +- .../explain/TransportExplainAction.java | 2 +- .../search/AbstractSearchAsyncAction.java | 4 +- .../search/CanMatchPreFilterSearchPhase.java | 2 +- .../search/QueryPhaseResultConsumer.java | 4 +- .../action/search/SearchPhaseContext.java | 2 +- .../action/support/TransportAction.java | 4 +- .../PendingReplicationActions.java | 2 +- .../TransportReplicationAction.java | 4 +- .../replication/TransportWriteAction.java | 2 +- .../java/org/opensearch/client/Client.java | 2 +- .../cluster/coordination/Coordinator.java | 2 +- .../ElectionSchedulerFactory.java | 2 +- .../cluster/coordination/LeaderChecker.java | 2 +- .../coordination/PreVoteCollector.java | 2 +- .../service/ClusterApplierService.java | 2 +- .../java/org/opensearch/common/StopWatch.java | 2 +- .../bytes/ReleasableBytesReference.java | 2 +- .../common/component/LifecycleComponent.java | 2 +- .../common/compress/DeflateCompressor.java | 4 +- .../concurrent/RefCountedReleasable.java | 2 +- .../stream/ReleasableBytesStreamOutput.java | 4 +- .../common/io/stream/StreamInput.java | 313 +-- .../common/io/stream/StreamOutput.java | 128 - .../common/lucene/index/FreqTermsEnum.java | 4 +- .../opensearch/common/recycler/Recycler.java | 2 +- .../common/util/AbstractBigArray.java | 2 +- .../opensearch/common/util/AbstractHash.java | 2 +- .../common/util/AbstractPagedHashMap.java | 2 +- .../org/opensearch/common/util/BigArray.java | 2 +- .../org/opensearch/common/util/BigArrays.java | 4 +- .../org/opensearch/common/util/BitArray.java | 4 +- .../opensearch/common/util/BytesRefHash.java | 4 +- .../org/opensearch/common/util/LongHash.java | 2 +- .../opensearch/common/util/LongLongHash.java | 2 +- .../common/util/LongObjectPagedHashMap.java | 2 +- .../common/util/concurrent/KeyedLock.java | 2 +- .../util/concurrent/ReleasableLock.java | 4 +- .../org/opensearch/env/NodeEnvironment.java | 6 +- .../opensearch/gateway/AsyncShardFetch.java | 2 +- .../opensearch/gateway/GatewayAllocator.java | 2 +- .../gateway/PersistedClusterStateService.java | 10 +- .../opensearch/http/DefaultRestChannel.java | 4 +- .../opensearch/index/IndexingPressure.java | 2 +- .../index/IndexingPressureService.java | 2 +- .../index/ShardIndexingPressure.java | 2 +- .../org/opensearch/index/engine/Engine.java | 4 +- .../index/engine/InternalEngine.java | 2 +- .../index/engine/LiveVersionMap.java | 2 +- .../index/engine/SoftDeletesPolicy.java | 2 +- .../index/fielddata/LeafFieldData.java | 2 +- .../index/seqno/RetentionLeaseActions.java | 2 +- .../opensearch/index/shard/IndexShard.java | 4 +- .../shard/IndexShardOperationPermits.java | 2 +- .../index/shard/RefreshListeners.java | 2 +- .../index/translog/RemoteFsTranslog.java | 6 +- .../opensearch/index/translog/Translog.java | 4 +- .../translog/TranslogDeletionPolicy.java | 2 +- .../index/translog/TranslogWriter.java | 2 +- .../opensearch/indices/IndicesService.java | 10 +- .../indices/RunUnderPrimaryPermit.java | 2 +- .../cache/IndicesFieldDataCache.java | 2 +- .../LocalStorePeerRecoverySourceHandler.java | 2 +- .../indices/recovery/MultiFileWriter.java | 2 +- .../recovery/RecoverySourceHandler.java | 4 +- .../RemoteStorePeerRecoverySourceHandler.java | 2 +- .../SegmentFileTransferHandler.java | 2 +- .../main/java/org/opensearch/node/Node.java | 4 +- .../blobstore/BlobStoreRepository.java | 6 +- .../org/opensearch/rest/RestResponse.java | 3 +- .../search/DefaultSearchContext.java | 2 +- .../org/opensearch/search/SearchService.java | 4 +- .../search/aggregations/Aggregator.java | 2 +- .../bucket/BucketsAggregator.java | 2 +- .../bucket/composite/BinaryValuesSource.java | 2 +- .../bucket/composite/CompositeAggregator.java | 2 +- .../CompositeValuesCollectorQueue.java | 4 +- .../bucket/composite/DoubleValuesSource.java | 2 +- .../composite/GlobalOrdinalValuesSource.java | 2 +- .../bucket/composite/LongValuesSource.java | 2 +- .../SingleDimensionValuesSource.java | 2 +- .../composite/UnsignedLongValuesSource.java | 2 +- .../AbstractHistogramAggregator.java | 2 +- .../AutoDateHistogramAggregator.java | 2 +- .../histogram/DateHistogramAggregator.java | 2 +- .../DateRangeHistogramAggregator.java | 2 +- .../VariableWidthHistogramAggregator.java | 4 +- .../sampler/BestDocsDeferringCollector.java | 4 +- .../DiversifiedMapSamplerAggregator.java | 2 +- .../bucket/sampler/SamplerAggregator.java | 4 +- .../bucket/terms/BytesKeyedBucketOrds.java | 4 +- .../GlobalOrdinalsStringTermsAggregator.java | 4 +- .../bucket/terms/LongKeyedBucketOrds.java | 2 +- .../bucket/terms/LongRareTermsAggregator.java | 2 +- .../terms/MapStringTermsAggregator.java | 4 +- .../bucket/terms/MultiTermsAggregator.java | 2 +- .../bucket/terms/NumericTermsAggregator.java | 4 +- .../bucket/terms/SignificanceLookup.java | 4 +- .../SignificantTextAggregatorFactory.java | 2 +- .../terms/StringRareTermsAggregator.java | 2 +- .../AbstractHDRPercentilesAggregator.java | 3 +- .../metrics/AbstractHyperLogLogPlusPlus.java | 2 +- .../AbstractTDigestPercentilesAggregator.java | 2 +- .../aggregations/metrics/AvgAggregator.java | 2 +- .../metrics/CardinalityAggregator.java | 4 +- .../metrics/ExtendedStatsAggregator.java | 4 +- .../metrics/GeoCentroidAggregator.java | 2 +- .../metrics/HyperLogLogPlusPlus.java | 4 +- .../metrics/HyperLogLogPlusPlusSparse.java | 4 +- .../aggregations/metrics/MaxAggregator.java | 2 +- .../MedianAbsoluteDeviationAggregator.java | 2 +- .../aggregations/metrics/MinAggregator.java | 2 +- .../metrics/ScriptedMetricAggregator.java | 2 +- .../aggregations/metrics/StatsAggregator.java | 2 +- .../aggregations/metrics/SumAggregator.java | 2 +- .../metrics/TopHitsAggregator.java | 2 +- .../metrics/ValueCountAggregator.java | 2 +- .../metrics/WeightedAvgAggregator.java | 2 +- .../search/internal/ContextIndexSearcher.java | 2 +- .../search/internal/PitReaderContext.java | 4 +- .../search/internal/ReaderContext.java | 4 +- .../search/internal/SearchContext.java | 4 +- .../opensearch/search/sort/BucketedSort.java | 4 +- .../org/opensearch/tasks/TaskManager.java | 4 +- .../transport/InboundAggregator.java | 4 +- .../opensearch/transport/InboundDecoder.java | 2 +- .../opensearch/transport/InboundMessage.java | 4 +- .../opensearch/transport/InboundPipeline.java | 4 +- .../opensearch/transport/OutboundHandler.java | 4 +- .../transport/RequestHandlerRegistry.java | 6 +- .../transport/TaskTransportChannel.java | 2 +- .../transport/TcpTransportChannel.java | 2 +- .../transport/TransportService.java | 2 +- .../ExceptionSerializationTests.java | 2 +- .../node/tasks/TaskManagerTestCase.java | 2 +- ...TransportResyncReplicationActionTests.java | 2 +- .../action/search/MockSearchPhaseContext.java | 2 +- .../TransportReplicationActionTests.java | 2 +- ...ReplicationAllPermitsAcquisitionTests.java | 2 +- ...rtWriteActionForIndexingPressureTests.java | 2 +- .../TransportWriteActionTests.java | 2 +- .../ElectionSchedulerFactoryTests.java | 2 +- .../coordination/PreVoteCollectorTests.java | 2 +- .../cluster/service/TaskExecutorTests.java | 2 +- .../opensearch/common/ReleasablesTests.java | 4 +- .../common/util/BinarySearcherTests.java | 2 +- .../util/concurrent/KeyedLockTests.java | 2 +- .../util/concurrent/ReleasableLockTests.java | 2 +- .../http/DefaultRestChannelTests.java | 4 +- .../index/IndexingPressureServiceTests.java | 2 +- .../index/IndexingPressureTests.java | 2 +- ...exingPressureConcurrentExecutionTests.java | 2 +- .../index/ShardIndexingPressureTests.java | 2 +- .../index/engine/LiveVersionMapTests.java | 2 +- .../index/engine/SoftDeletesPolicyTests.java | 2 +- .../RecoveryDuringReplicationTests.java | 2 +- .../seqno/RetentionLeaseActionsTests.java | 2 +- .../IndexShardOperationPermitsTests.java | 4 +- .../index/shard/IndexShardTests.java | 8 +- .../index/shard/RefreshListenersTests.java | 2 +- .../RemoteStoreRefreshListenerTests.java | 2 +- .../SegmentReplicationIndexShardTests.java | 2 +- .../translog/TranslogDeletionPolicyTests.java | 2 +- ...alStorePeerRecoverySourceHandlerTests.java | 2 +- .../metrics/InternalCardinalityTests.java | 2 +- .../search/sort/BucketedSortTestCase.java | 2 +- .../opensearch/tasks/TaskManagerTests.java | 4 +- .../transport/InboundPipelineTests.java | 2 +- .../transport/TransportDecompressorTests.java | 2 +- .../AbstractCoordinatorTestCase.java | 2 +- ...enSearchIndexLevelReplicationTestCase.java | 4 +- .../index/shard/IndexShardTestCase.java | 2 +- .../aggregations/AggregatorTestCase.java | 4 +- .../opensearch/test/InternalTestCluster.java | 2 +- .../test/transport/MockTransport.java | 3 +- .../transport/nio/MockNioTransport.java | 4 +- 202 files changed, 2023 insertions(+), 1648 deletions(-) rename {server/src/main/java/org/opensearch => libs/core/src/main/java/org/opensearch/core}/common/lease/Releasable.java (92%) rename {server/src/main/java/org/opensearch => libs/core/src/main/java/org/opensearch/core}/common/lease/Releasables.java (99%) rename {server/src/main/java/org/opensearch => libs/core/src/main/java/org/opensearch/core}/common/lease/package-info.java (85%) diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index ece87b3eed38a..89e81c64fe205 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -9,4 +9,4 @@