@Override public long getRowCount(Session session) { if (multiVersion) { Integer i = sessionRowCount.get(session.getId()); long count = i == null ? 0 : i.intValue(); count += rowCount; count -= rowCountDiff; return count; } return rowCount; }
@Override public long getRowCount(Session session) { if (database.isMultiVersion()) { Integer i = sessionRowCount.get(session.getId()); long count = i == null ? 0 : i.intValue(); count += rowCount; count -= rowCountDiff; return count; } return rowCount; }
/** * Get a unique temporary table name. * * @param baseName the prefix of the returned name * @param session the session * @return a unique name */ public synchronized String getTempTableName(String baseName, Session session) { String tempName; do { tempName = baseName + "_COPY_" + session.getId() + "_" + nextTempTableId++; } while (mainSchema.findTableOrView(session, tempName) != null); return tempName; }
/** * Lock the metadata table for updates. * * @param session the session * @return whether it was already locked before by this session */ public boolean lockMeta(Session session) { // this method can not be synchronized on the database object, // as unlocking is also synchronized on the database object - // so if locking starts just before unlocking, locking could // never be successful if (meta == null) { return true; } if (SysProperties.CHECK2) { final Session prev = META_LOCK_DEBUGGING.get(); if (prev == null) { META_LOCK_DEBUGGING.set(session); META_LOCK_DEBUGGING_STACK.set(new Throwable("Last meta lock granted in this stack trace, "+ "this is debug information for following IllegalStateException")); } else if (prev != session) { META_LOCK_DEBUGGING_STACK.get().printStackTrace(); throw new IllegalStateException("meta currently locked by " + prev +", sessionid="+ prev.getId() + " and trying to be locked by different session, " + session +", sessionid="+ session.getId() + " on same thread"); } } return meta.lock(session, true, true); }
private synchronized void closeAllSessionsException(Session except) { Session[] all = userSessions.toArray(new Session[userSessions.size()]); for (Session s : all) { if (s != except) { try { // must roll back, otherwise the session is removed and // the transaction log that contains its uncommitted // operations as well s.rollback(); s.close(); } catch (DbException e) { trace.error(e, "disconnecting session #{0}", s.getId()); } } } }
private void traceLock(Session session, boolean exclusive, String s) { if (traceLock.isDebugEnabled()) { traceLock.debug("{0} {1} {2} {3}", session.getId(), exclusive ? "exclusive write lock" : "shared read lock", s, getName()); } }
@Override public void add(Session session, Row row) { // in-memory if (firstFree == -1) { int key = rows.size(); row.setKey(key); rows.add(row); } else { long key = firstFree; Row free = rows.get((int) key); firstFree = free.getKey(); row.setKey(key); rows.set((int) key, row); } row.setDeleted(false); if (database.isMultiVersion()) { if (delta == null) { delta = new HashSet<>(); } boolean wasDeleted = delta.remove(row); if (!wasDeleted) { delta.add(row); } incrementRowCount(session.getId(), 1); } rowCount++; }
/** * Create a session for the given user. * * @param user the user * @return the session, or null if the database is currently closing * @throws DbException if the database is in exclusive mode */ synchronized Session createSession(User user) { if (closing) { return null; } if (exclusiveSession.get() != null) { throw DbException.get(ErrorCode.DATABASE_IS_IN_EXCLUSIVE_MODE); } Session session = new Session(this, user, ++nextSessionId); userSessions.add(session); trace.info("connecting session #{0} to {1}", session.getId(), databaseName); if (delayedCloser != null) { delayedCloser.reset(); delayedCloser = null; } return session; }
private void traceLock(Session session, boolean exclusive, TraceLockEvent eventEnum, String extraInfo) { if (traceLock.isDebugEnabled()) { traceLock.debug("{0} {1} {2} {3} {4}", session.getId(), exclusive ? "exclusive write lock" : "shared read lock", eventEnum.getEventText(), getName(), extraInfo); } }
@Override public boolean next() { if (multiVersion) { while (true) { if (delta != null) { if (!delta.hasNext()) { delta = null; row = null; continue; } row = delta.next(); if (!row.isDeleted() || row.getSessionId() == session.getId()) { continue; } } else { row = scan.getNextRow(row); if (row != null && row.getSessionId() != 0 && row.getSessionId() != session.getId()) { continue; } } break; } return row != null; } row = scan.getNextRow(row); return row != null; }
@Override public boolean next() { if (!multiVersion) { nextRow(); return checkMax(); } while (true) { if (delta != null) { if (!delta.hasNext()) { delta = null; row = null; continue; } row = delta.next(); if (!row.isDeleted() || row.getSessionId() == session.getId()) { continue; } } else { nextRow(); if (row != null && row.getSessionId() != 0 && row.getSessionId() != session.getId()) { continue; } } break; } return checkMax(); }
delta.add(row); incrementRowCount(session.getId(), -1);
/** * Check if there is an uncommitted row with the given key * within a different session. * * @param session the original session * @param row the row (only the key is checked) * @return true if there is an uncommitted row */ public boolean isUncommittedFromOtherSession(Session session, Row row) { Cursor c = delta.find(session, row, row); while (c.next()) { Row r = c.get(); return r.getSessionId() != session.getId(); } return false; }
/** * A table is truncated. * * @param session the session * @param tableId the table id */ void logTruncate(Session session, int tableId) { if (trace.isDebugEnabled()) { trace.debug("log truncate s: " + session.getId() + " table: " + tableId); } session.addLogPos(logSectionId, logPos); logPos++; Data buffer = getBuffer(); buffer.writeByte((byte) TRUNCATE); buffer.writeVarInt(session.getId()); buffer.writeVarInt(tableId); write(buffer); }
private static boolean cancelStatement(Session session, int targetSessionId) { session.getUser().checkAdmin(); Session[] sessions = session.getDatabase().getSessions(false); for (Session s : sessions) { if (s.getId() == targetSessionId) { Command c = s.getCurrentCommand(); if (c == null) { return false; } c.cancel(); return true; } } return false; }
int newId = session.getId(); if (old == 0) { row.setSessionId(newId);
delta.add(row); incrementRowCount(session.getId(), 1);
checkOpen(); openForWriting(); log.commit(session.getId()); long size = log.getSize(); if (size - logSizeBase > maxLogSize / 2) {