@@ -86,9 +86,13 @@ public void close() throws Exception {
86
86
// Fail all the pending items
87
87
MetadataStoreException ex =
88
88
new MetadataStoreException .AlreadyClosedException ("Metadata store is getting closed" );
89
- readOps .drain (op -> op .getFuture ().completeExceptionally (ex ));
90
- writeOps .drain (op -> op .getFuture ().completeExceptionally (ex ));
91
-
89
+ MetadataOp op ;
90
+ while ((op = readOps .poll ()) != null ) {
91
+ op .getFuture ().completeExceptionally (ex );
92
+ }
93
+ while ((op = writeOps .poll ()) != null ) {
94
+ op .getFuture ().completeExceptionally (ex );
95
+ }
92
96
scheduledTask .cancel (true );
93
97
}
94
98
super .close ();
@@ -98,7 +102,13 @@ public void close() throws Exception {
98
102
private void flush () {
99
103
while (!readOps .isEmpty ()) {
100
104
List <MetadataOp > ops = new ArrayList <>();
101
- readOps .drain (ops ::add , maxOperations );
105
+ for (int i = 0 ; i < maxOperations ; i ++) {
106
+ MetadataOp op = readOps .poll ();
107
+ if (op == null ) {
108
+ break ;
109
+ }
110
+ ops .add (op );
111
+ }
102
112
internalBatchOperation (ops );
103
113
}
104
114
@@ -167,6 +177,11 @@ public void updateMetadataEventSynchronizer(MetadataEventSynchronizer synchroniz
167
177
}
168
178
169
179
private void enqueue (MessagePassingQueue <MetadataOp > queue , MetadataOp op ) {
180
+ if (isClosed ()) {
181
+ MetadataStoreException ex = new MetadataStoreException .AlreadyClosedException ();
182
+ op .getFuture ().completeExceptionally (ex );
183
+ return ;
184
+ }
170
185
if (enabled ) {
171
186
if (!queue .offer (op )) {
172
187
// Execute individually if we're failing to enqueue
@@ -182,6 +197,12 @@ private void enqueue(MessagePassingQueue<MetadataOp> queue, MetadataOp op) {
182
197
}
183
198
184
199
private void internalBatchOperation (List <MetadataOp > ops ) {
200
+ if (isClosed ()) {
201
+ MetadataStoreException ex =
202
+ new MetadataStoreException .AlreadyClosedException ();
203
+ ops .forEach (op -> op .getFuture ().completeExceptionally (ex ));
204
+ return ;
205
+ }
185
206
long now = System .currentTimeMillis ();
186
207
for (MetadataOp op : ops ) {
187
208
this .batchMetadataStoreStats .recordOpWaiting (now - op .created ());
0 commit comments