@Override public boolean isMvcc() { return database.isMultiVersion(); }
private void incrementRowCount(int sessionId, int count) { if (database.isMultiVersion()) { Integer id = sessionId; Integer c = sessionRowCount.get(id); int current = c == null ? 0 : c.intValue(); sessionRowCount.put(id, current + count); rowCountDiff += count; } }
@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; }
@Override public Cursor find(Session session, SearchRow first, SearchRow last) { return new ScanCursor(session, this, database.isMultiVersion()); }
public ScanIndex(RegularTable table, int id, IndexColumn[] columns, IndexType indexType) { initBaseIndex(table, id, table.getName() + "_DATA", columns, indexType); if (database.isMultiVersion()) { sessionRowCount = new HashMap<>(); } else { sessionRowCount = null; } tableData = table; }
@Override public void commit(int operation, Row row) { if (database.isMultiVersion()) { if (delta != null) { delta.remove(row); } incrementRowCount(row.getSessionId(), operation == UndoLogRecord.DELETE ? 1 : -1); } }
@Override public long getRowCount(Session session) { if (database.isMultiVersion()) { return getScanIndex(session).getRowCount(session); } return rowCount; }
/** * Unlock all read locks. This is done if the transaction isolation mode is * READ_COMMITTED. */ public void unlockReadLocks() { if (database.isMultiVersion()) { // MVCC: keep shared locks (insert / update / delete) return; } // locks is modified in the loop for (int i = 0; i < locks.size(); i++) { Table t = locks.get(i); if (!t.isLockedExclusively()) { synchronized (database) { t.unlock(this); locks.remove(i); } i--; } } }
@Override public void setForUpdate(boolean b) { this.isForUpdate = b; if (session.getDatabase().getSettings().selectForUpdateMvcc && session.getDatabase().isMultiVersion()) { isForUpdateMvcc = b; } }
@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++; }
@Override public void remove(Session session, Row row) { if (!database.isMultiVersion() && rowCount == 1) { rows = New.arrayList(); firstFree = -1; firstFree = key; if (database.isMultiVersion()) {
private void checkRowCount(Session session, Index index, int offset) { if (SysProperties.CHECK && !database.isMultiVersion()) { if (!(index instanceof PageDelegateIndex)) { long rc = index.getRowCount(session); if (rc != rowCount + offset) { DbException.throwInternalError( "rowCount expected " + (rowCount + offset) + " got " + rc + " " + getName() + "." + index.getName()); } } } }
return lockExclusiveSession != null; if (!forceLockEvenInMvcc && database.isMultiVersion()) {
@Override public void truncate(Session session) { rows = New.arrayList(); firstFree = -1; if (tableData.getContainsLargeObject() && tableData.isPersistData()) { database.getLobStorage().removeAllForTable(table.getId()); } tableData.setRowCount(0); rowCount = 0; rowCountDiff = 0; if (database.isMultiVersion()) { sessionRowCount.clear(); } }
int lockMode = database.getLockMode(); if (lockMode != Constants.LOCK_MODE_OFF && !database.isMultiVersion()) { TableType tableType = log.getTable().getTableType(); if (!locks.contains(log.getTable()) if (database.isMultiVersion()) {
@Override public void removeRow(Session session, Row row) { if (database.isMultiVersion()) { if (row.isDeleted()) { throw DbException.get(ErrorCode.CONCURRENT_UPDATE_1, getName());
private synchronized void addMeta(Session session, DbObject obj) { int id = obj.getId(); if (id > 0 && !starting && !obj.isTemporary()) { Row r = meta.getTemplateRow(); MetaRecord rec = new MetaRecord(obj); rec.setRecord(r); objectIds.set(id); if (SysProperties.CHECK) { verifyMetaLocked(session); } meta.addRow(session, r); if (isMultiVersion()) { // TODO this should work without MVCC, but avoid risks at the // moment session.log(meta, UndoLogRecord.INSERT, r); } } }
@Override public void addRow(Session session, Row row) { lastModificationId = database.getNextModificationDataId(); if (database.isMultiVersion()) { row.setSessionId(session.getId());
public PageDataIndex(RegularTable table, int id, IndexColumn[] columns, IndexType indexType, boolean create, Session session) { initBaseIndex(table, id, table.getName() + "_DATA", columns, indexType); this.multiVersion = database.isMultiVersion();