This is an automated email from the ASF dual-hosted git repository. kturner pushed a commit to branch 1.8 in repository https://gitbox.apache.org/repos/asf/accumulo.git
commit 0bd076eda1753e76f2a64a919a21e57ebbc96140 Merge: eb15e45 f40f7c1 Author: Keith Turner <ktur...@apache.org> AuthorDate: Wed Feb 14 17:32:04 2018 -0500 Merge remote-tracking branch 'upstream/1.7' into 1.8 .../java/org/apache/accumulo/tserver/session/SessionManager.java | 5 ----- 1 file changed, 5 deletions(-) diff --cc server/tserver/src/main/java/org/apache/accumulo/tserver/session/SessionManager.java index b04a367,a03c032..e0fb795 --- a/server/tserver/src/main/java/org/apache/accumulo/tserver/session/SessionManager.java +++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/session/SessionManager.java @@@ -85,21 -70,20 +85,20 @@@ public class SessionManager }; SimpleTimer.getInstance(conf).schedule(r, 0, Math.max(maxIdle / 2, 1000)); - } - public synchronized long createSession(Session session, boolean reserve) { + public long createSession(Session session, boolean reserve) { long sid = random.nextLong(); - while (sessions.containsKey(sid)) { - sid = random.nextLong(); + synchronized (session) { + Preconditions.checkArgument(session.state == State.NEW); + session.state = reserve ? State.RESERVED : State.UNRESERVED; + session.startTime = session.lastAccessTime = System.currentTimeMillis(); } - sessions.put(sid, session); - - session.reserved = reserve; - - session.startTime = session.lastAccessTime = System.currentTimeMillis(); + while (sessions.putIfAbsent(sid, session) != null) { + sid = random.nextLong(); + } return sid; } @@@ -128,67 -108,44 +127,65 @@@ } - public synchronized Session reserveSession(long sessionId, boolean wait) { + public Session reserveSession(long sessionId, boolean wait) { Session session = sessions.get(sessionId); - if (session != null) { - while (wait && session.reserved) { - try { - wait(1000); - } catch (InterruptedException e) { - throw new RuntimeException(); + synchronized (session) { + + if (session.state == State.REMOVED) + return null; + + while (wait && session.state == State.RESERVED) { + try { + session.wait(1000); + } catch (InterruptedException e) { + throw new RuntimeException(); + } } - } - if (session.reserved) - throw new IllegalStateException(); - session.reserved = true; + if (session.state == State.RESERVED) + throw new IllegalStateException("Attempted to reserved session that is already reserved " + sessionId); + if (session.state == State.REMOVED) + return null; + session.state = State.RESERVED; + } } return session; } - public synchronized void unreserveSession(Session session) { - if (!session.reserved) - throw new IllegalStateException(); - notifyAll(); - session.reserved = false; - session.lastAccessTime = System.currentTimeMillis(); + public void unreserveSession(Session session) { + synchronized (session) { + if (session.state == State.REMOVED) + return; + if (session.state != State.RESERVED) + throw new IllegalStateException("Cannon unreserve, state: " + session.state); + session.notifyAll(); + session.state = State.UNRESERVED; + session.lastAccessTime = System.currentTimeMillis(); + } } - public synchronized void unreserveSession(long sessionId) { + public void unreserveSession(long sessionId) { Session session = getSession(sessionId); - if (session != null) + if (session != null) { unreserveSession(session); + } - } - public synchronized Session getSession(long sessionId) { + public Session getSession(long sessionId) { Session session = sessions.get(sessionId); - if (session != null) - session.lastAccessTime = System.currentTimeMillis(); + + if (session != null) { + synchronized (session) { + if (session.state == State.REMOVED) { + return null; + } + session.lastAccessTime = System.currentTimeMillis(); + } + } + return session; } @@@ -240,33 -188,27 +237,32 @@@ } } } + } - List<Session> sessionsToCleanup = new ArrayList<>(); + // do clean up outside of lock for TabletServer in a synchronized block for simplicity vice a synchronized list - // do clean up outside of lock for TabletServer - for (Session session : idleSessions) { - if (!session.cleanup()) { - sessionsToCleanup.add(session); - } - } + synchronized (idleSessions) { + sessionsToCleanup.addAll(idleSessions); + idleSessions.clear(); + } - synchronized (this) { - idleSessions.clear(); - idleSessions.addAll(sessionsToCleanup); - } + // perform cleanup for all of the sessions + for (Session session : sessionsToCleanup) { + if (!session.cleanup()) + synchronized (idleSessions) { + idleSessions.add(session); + } } - } - public synchronized void removeIfNotAccessed(final long sessionId, final long delay) { + public void removeIfNotAccessed(final long sessionId, final long delay) { Session session = sessions.get(sessionId); if (session != null) { - final long removeTime = session.lastAccessTime; + long tmp; + synchronized (session) { + tmp = session.lastAccessTime; + } + final long removeTime = tmp; TimerTask r = new TimerTask() { @Override public void run() { -- To stop receiving notification emails like this one, please contact ktur...@apache.org.