@@ -1083,6 +1083,55 @@ public void testConcurrentGetAndFlush() throws Exception {
1083
1083
latestGetResult .get ().close ();
1084
1084
}
1085
1085
1086
+ public void testUpdateOperationForAppendOnlyIndex () throws Exception {
1087
+ Settings .Builder settings = Settings .builder ()
1088
+ .put (defaultSettings .getSettings ())
1089
+ .put (IndexMetadata .INDEX_APPEND_ONLY_ENABLED_SETTING .getKey (), "true" );
1090
+ final IndexMetadata indexMetadata = IndexMetadata .builder (defaultSettings .getIndexMetadata ()).settings (settings ).build ();
1091
+ final IndexSettings indexSettings = IndexSettingsModule .newIndexSettings (indexMetadata );
1092
+ final AtomicLong globalCheckpoint = new AtomicLong (SequenceNumbers .NO_OPS_PERFORMED );
1093
+ try (
1094
+ Store store = createStore ();
1095
+ InternalEngine engine = createUpdateOnlyEngine (
1096
+ config (indexSettings , store , createTempDir (), newMergePolicy (), null , null , globalCheckpoint ::get )
1097
+ )
1098
+ ) {
1099
+ engine .refresh ("warm_up" );
1100
+ Engine .Searcher searchResult = engine .acquireSearcher ("test" );
1101
+ searchResult .close ();
1102
+
1103
+ final BiFunction <String , Engine .SearcherScope , Engine .Searcher > searcherFactory = engine ::acquireSearcher ;
1104
+
1105
+ // create a document
1106
+ Document document = testDocumentWithTextField ();
1107
+ document .add (new Field (SourceFieldMapper .NAME , BytesReference .toBytes (B_1 ), SourceFieldMapper .Defaults .FIELD_TYPE ));
1108
+ ParsedDocument doc = testParsedDocument ("1" , null , document , B_1 , null );
1109
+ expectThrows (AlreadyClosedException .class , () -> engine .index (indexForDoc (doc )));
1110
+ }
1111
+ }
1112
+
1113
+ private InternalEngine createUpdateOnlyEngine (EngineConfig config ) throws IOException {
1114
+ final Store store = config .getStore ();
1115
+ final Directory directory = store .directory ();
1116
+ if (Lucene .indexExists (directory ) == false ) {
1117
+ store .createEmpty (config .getIndexSettings ().getIndexVersionCreated ().luceneVersion );
1118
+ final String translogUuid = Translog .createEmptyTranslog (
1119
+ config .getTranslogConfig ().getTranslogPath (),
1120
+ SequenceNumbers .NO_OPS_PERFORMED ,
1121
+ shardId ,
1122
+ primaryTerm .get ()
1123
+ );
1124
+ store .associateIndexWithNewTranslog (translogUuid );
1125
+ }
1126
+
1127
+ return new InternalEngine (config ) {
1128
+ @ Override
1129
+ protected IndexingStrategy indexingStrategyForOperation (Index index ) throws IOException {
1130
+ return IndexingStrategy .processNormally (false , 0 , 0 );
1131
+ }
1132
+ };
1133
+ }
1134
+
1086
1135
public void testSimpleOperations () throws Exception {
1087
1136
engine .refresh ("warm_up" );
1088
1137
Engine .Searcher searchResult = engine .acquireSearcher ("test" );
0 commit comments