Merge branch 'gerrit/trinity' into 'master'

Change-Id: Id5bc38ec8fd856550f118668e17e73b9420fdf5a
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/context/GlobalVirtualBufferCache.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/context/GlobalVirtualBufferCache.java
index a4663ed..1ba9ac6 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/context/GlobalVirtualBufferCache.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/context/GlobalVirtualBufferCache.java
@@ -177,13 +177,16 @@
             // 2. there are still some active readers and memory cannot be reclaimed.
             // But for both cases, we will notify all primary index op trackers to let their writers retry,
             // if they have been blocked. Moreover, we will check whether more flushes are needed.
+            List<ILSMOperationTracker> opTrackers = new ArrayList<>();
             synchronized (this) {
                 final int size = primaryIndexes.size();
                 for (int i = 0; i < size; i++) {
-                    ILSMOperationTracker opTracker = primaryIndexes.get(i).getOperationTracker();
-                    synchronized (opTracker) {
-                        opTracker.notifyAll();
-                    }
+                    opTrackers.add(primaryIndexes.get(i).getOperationTracker());
+                }
+            }
+            for (ILSMOperationTracker opTracker : opTrackers) {
+                synchronized (opTracker) {
+                    opTracker.notifyAll();
                 }
             }
             checkAndNotifyFlushThread();
diff --git a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/PartitionResourcesListTask.java b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/PartitionResourcesListTask.java
index 0f5949e..0856969 100644
--- a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/PartitionResourcesListTask.java
+++ b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/messaging/PartitionResourcesListTask.java
@@ -18,6 +18,8 @@
  */
 package org.apache.asterix.replication.messaging;
 
+import static org.apache.asterix.common.utils.StorageConstants.METADATA_PARTITION;
+
 import java.io.DataInput;
 import java.io.DataOutputStream;
 import java.io.IOException;
@@ -51,6 +53,10 @@
     @Override
     public void perform(INcApplicationContext appCtx, IReplicationWorker worker) throws HyracksDataException {
         LOGGER.debug("processing {}", this);
+        if (METADATA_PARTITION == partition && appCtx.getReplicaManager().getPartitions().contains(partition)) {
+            LOGGER.warn("received request to get metadata files from non-master {}", worker.getRemoteAddress());
+            throw new IllegalStateException();
+        }
         final PersistentLocalResourceRepository localResourceRepository =
                 (PersistentLocalResourceRepository) appCtx.getLocalResourceRepository();
         localResourceRepository.cleanup(partition);