-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIST-1157] NullPointerException in QueryAllocationManager (#1160)
This PR closes #1157 via * Fix `NullPointerException` in ApplicationAwareQueryAllocationManager by adopting global read/write lock. * Update `AppTaskInfoMap` up-to-date.
- Loading branch information
1 parent
10a2e52
commit 3e14542
Showing
18 changed files
with
474 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
mist-core/src/main/java/edu/snu/mist/core/master/TaskInfoRWLock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright (C) 2018 Seoul National University | ||
* | ||
* Licensed 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 edu.snu.mist.core.master; | ||
|
||
import javax.inject.Inject; | ||
import java.util.Arrays; | ||
import java.util.concurrent.locks.ReentrantReadWriteLock; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* The shared read/write lock used for synchronizing adding / deleting task info | ||
* based on ReentrantReadWriteLock class. | ||
*/ | ||
public final class TaskInfoRWLock extends ReentrantReadWriteLock { | ||
|
||
private static final Logger LOG = Logger.getLogger(TaskInfoRWLock.class.getName()); | ||
|
||
private final LoggableReadLock loggableReadLock; | ||
|
||
private final LoggableWriteLock loggableWriteLock; | ||
|
||
// The injectable constructor. | ||
@Inject | ||
private TaskInfoRWLock() { | ||
super(); | ||
// Do nothing. | ||
this.loggableReadLock = new LoggableReadLock(this); | ||
this.loggableWriteLock = new LoggableWriteLock(this); | ||
} | ||
|
||
/** | ||
* This method utilizes getReadHoldCount() for determining | ||
* whether the current thread is holding a read lock or not. | ||
* @return true / false | ||
*/ | ||
public boolean isReadHoldByCurrentThread() { | ||
return this.getReadHoldCount() > 0 || this.isWriteLockedByCurrentThread(); | ||
} | ||
|
||
@Override | ||
public WriteLock writeLock() { | ||
return loggableWriteLock; | ||
} | ||
|
||
@Override | ||
public ReadLock readLock() { | ||
return loggableReadLock; | ||
} | ||
|
||
private static class LoggableReadLock extends ReadLock { | ||
public LoggableReadLock(final ReentrantReadWriteLock lock) { | ||
super(lock); | ||
} | ||
|
||
@Override | ||
public void lock() { | ||
if (LOG.isLoggable(Level.FINE)) { | ||
LOG.log(Level.FINE, "Acquiring Readlock on TaskInfoRWLock: {0}", | ||
Arrays.toString(Thread.currentThread().getStackTrace())); | ||
} | ||
super.lock(); | ||
} | ||
|
||
@Override | ||
public void unlock() { | ||
if (LOG.isLoggable(Level.FINE)) { | ||
LOG.log(Level.FINE, "Releasing Readlock on TaskInfoRWLock: {0}", | ||
Arrays.toString(Thread.currentThread().getStackTrace())); | ||
} | ||
super.unlock(); | ||
} | ||
} | ||
|
||
private static class LoggableWriteLock extends WriteLock { | ||
public LoggableWriteLock(final ReentrantReadWriteLock lock) { | ||
super(lock); | ||
} | ||
|
||
@Override | ||
public void lock() { | ||
if (LOG.isLoggable(Level.FINE)) { | ||
LOG.log(Level.FINE, "Acquiring Writelock on TaskInfoRWLock: {0}", | ||
Arrays.toString(Thread.currentThread().getStackTrace())); | ||
} | ||
super.lock(); | ||
} | ||
|
||
@Override | ||
public void unlock() { | ||
if (LOG.isLoggable(Level.FINE)) { | ||
LOG.log(Level.FINE, "Releasing Readlock on TaskInfoRWLock: {0}", | ||
Arrays.toString(Thread.currentThread().getStackTrace())); | ||
} | ||
super.unlock(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
mist-core/src/main/java/edu/snu/mist/core/master/lb/AppTaskListMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (C) 2018 Seoul National University | ||
* | ||
* Licensed 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 edu.snu.mist.core.master.lb; | ||
|
||
import javax.inject.Inject; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
/** | ||
* The map which contains app-task mapping information. | ||
*/ | ||
public final class AppTaskListMap { | ||
|
||
private final ConcurrentMap<String, List<String>> innerMap; | ||
|
||
@Inject | ||
private AppTaskListMap() { | ||
this.innerMap = new ConcurrentHashMap<>(); | ||
} | ||
|
||
public synchronized void removeTask(final String removedTaskId) { | ||
for (final Map.Entry<String, List<String>> entry: innerMap.entrySet()) { | ||
final List<String> taskIdList = entry.getValue(); | ||
taskIdList.removeIf(taskId -> taskId.equals(removedTaskId)); | ||
if (taskIdList.isEmpty()) { | ||
innerMap.remove(entry.getKey()); | ||
} | ||
} | ||
} | ||
|
||
public synchronized void addTaskToApp(final String appId, final String taskId) { | ||
if (!innerMap.containsKey(appId)) { | ||
innerMap.putIfAbsent(appId, new ArrayList<>()); | ||
} | ||
innerMap.get(appId).add(taskId); | ||
} | ||
|
||
public synchronized List<String> getTaskListForApp(final String appId) { | ||
return innerMap.get(appId); | ||
} | ||
} |
Oops, something went wrong.