提交 0fe83909 authored 作者: Andrei Tokar's avatar Andrei Tokar

Rename fields to reflect actual type

Database.mvStore - > store
MVTableEngine.Store.store - > mvStore
上级 849484e9
...@@ -181,7 +181,7 @@ public abstract class Command implements CommandInterface { ...@@ -181,7 +181,7 @@ public abstract class Command implements CommandInterface {
startTimeNanos = 0; startTimeNanos = 0;
long start = 0; long start = 0;
Database database = session.getDatabase(); Database database = session.getDatabase();
Object sync = database.isMultiThreaded() || database.getMvStore() != null ? session : database; Object sync = database.isMultiThreaded() || database.getStore() != null ? session : database;
session.waitIfExclusiveModeEnabled(); session.waitIfExclusiveModeEnabled();
boolean callStop = true; boolean callStop = true;
boolean writing = !isReadOnly(); boolean writing = !isReadOnly();
...@@ -241,7 +241,7 @@ public abstract class Command implements CommandInterface { ...@@ -241,7 +241,7 @@ public abstract class Command implements CommandInterface {
public ResultWithGeneratedKeys executeUpdate(Object generatedKeysRequest) { public ResultWithGeneratedKeys executeUpdate(Object generatedKeysRequest) {
long start = 0; long start = 0;
Database database = session.getDatabase(); Database database = session.getDatabase();
Object sync = database.isMultiThreaded() || database.getMvStore() != null ? session : database; Object sync = database.isMultiThreaded() || database.getStore() != null ? session : database;
session.waitIfExclusiveModeEnabled(); session.waitIfExclusiveModeEnabled();
boolean callStop = true; boolean callStop = true;
boolean writing = !isReadOnly(); boolean writing = !isReadOnly();
...@@ -330,7 +330,7 @@ public abstract class Command implements CommandInterface { ...@@ -330,7 +330,7 @@ public abstract class Command implements CommandInterface {
} }
// Only in PageStore mode we need to sleep here to avoid busy wait loop // Only in PageStore mode we need to sleep here to avoid busy wait loop
Database database = session.getDatabase(); Database database = session.getDatabase();
if (database.getMvStore() == null) { if (database.getStore() == null) {
int sleep = 1 + MathUtils.randomInt(10); int sleep = 1 + MathUtils.randomInt(10);
while (true) { while (true) {
try { try {
......
...@@ -58,9 +58,9 @@ public class BackupCommand extends Prepared { ...@@ -58,9 +58,9 @@ public class BackupCommand extends Prepared {
throw DbException.get(ErrorCode.DATABASE_IS_NOT_PERSISTENT); throw DbException.get(ErrorCode.DATABASE_IS_NOT_PERSISTENT);
} }
try { try {
Store mvStore = db.getMvStore(); Store store = db.getStore();
if (mvStore != null) { if (store != null) {
mvStore.flush(); store.flush();
} }
String name = db.getName(); String name = db.getName();
name = FileUtils.getName(name); name = FileUtils.getName(name);
...@@ -83,12 +83,12 @@ public class BackupCommand extends Prepared { ...@@ -83,12 +83,12 @@ public class BackupCommand extends Prepared {
if (n.endsWith(Constants.SUFFIX_LOB_FILE)) { if (n.endsWith(Constants.SUFFIX_LOB_FILE)) {
backupFile(out, base, n); backupFile(out, base, n);
} }
if (n.endsWith(Constants.SUFFIX_MV_FILE) && mvStore != null) { if (n.endsWith(Constants.SUFFIX_MV_FILE) && store != null) {
MVStore s = mvStore.getStore(); MVStore s = store.getMvStore();
boolean before = s.getReuseSpace(); boolean before = s.getReuseSpace();
s.setReuseSpace(false); s.setReuseSpace(false);
try { try {
InputStream in = mvStore.getInputStream(); InputStream in = store.getInputStream();
backupFile(out, base, n, in); backupFile(out, base, n, in);
} finally { } finally {
s.setReuseSpace(before); s.setReuseSpace(before);
......
...@@ -83,7 +83,7 @@ public class Explain extends Prepared { ...@@ -83,7 +83,7 @@ public class Explain extends Prepared {
if (store != null) { if (store != null) {
store.statisticsStart(); store.statisticsStart();
} }
mvStore = db.getMvStore(); mvStore = db.getStore();
if (mvStore != null) { if (mvStore != null) {
mvStore.statisticsStart(); mvStore.statisticsStart();
} }
......
...@@ -218,7 +218,7 @@ public class Database implements DataHandler { ...@@ -218,7 +218,7 @@ public class Database implements DataHandler {
private final DbSettings dbSettings; private final DbSettings dbSettings;
private final long reconnectCheckDelayNs; private final long reconnectCheckDelayNs;
private int logMode; private int logMode;
private MVTableEngine.Store mvStore; private MVTableEngine.Store store;
private int retentionTime; private int retentionTime;
private boolean allowBuiltinAliasOverride; private boolean allowBuiltinAliasOverride;
private final AtomicReference<DbException> backgroundException = new AtomicReference<>(); private final AtomicReference<DbException> backgroundException = new AtomicReference<>();
...@@ -376,13 +376,13 @@ public class Database implements DataHandler { ...@@ -376,13 +376,13 @@ public class Database implements DataHandler {
powerOffCount = count; powerOffCount = count;
} }
public MVTableEngine.Store getMvStore() { public MVTableEngine.Store getStore() {
return mvStore; return store;
} }
public void setMvStore(MVTableEngine.Store mvStore) { public void setStore(MVTableEngine.Store store) {
this.mvStore = mvStore; this.store = store;
this.retentionTime = mvStore.getStore().getRetentionTime(); this.retentionTime = store.getMvStore().getRetentionTime();
} }
/** /**
...@@ -532,8 +532,8 @@ public class Database implements DataHandler { ...@@ -532,8 +532,8 @@ public class Database implements DataHandler {
try { try {
powerOffCount = -1; powerOffCount = -1;
stopWriter(); stopWriter();
if (mvStore != null) { if (store != null) {
mvStore.closeImmediately(); store.closeImmediately();
} }
if (pageStore != null) { if (pageStore != null) {
try { try {
...@@ -737,7 +737,7 @@ public class Database implements DataHandler { ...@@ -737,7 +737,7 @@ public class Database implements DataHandler {
getPageStore(); getPageStore();
} }
starting = false; starting = false;
if (mvStore == null) { if (store == null) {
writer = WriterThread.create(this, writeDelay); writer = WriterThread.create(this, writeDelay);
} else { } else {
setWriteDelay(writeDelay); setWriteDelay(writeDelay);
...@@ -753,8 +753,8 @@ public class Database implements DataHandler { ...@@ -753,8 +753,8 @@ public class Database implements DataHandler {
getPageStore(); getPageStore();
} }
} }
if(mvStore != null) { if(store != null) {
mvStore.getTransactionStore().init(); store.getTransactionStore().init();
} }
systemUser = new User(this, 0, SYSTEM_USER_NAME, true); systemUser = new User(this, 0, SYSTEM_USER_NAME, true);
mainSchema = new Schema(this, 0, Constants.SCHEMA_MAIN, systemUser, true); mainSchema = new Schema(this, 0, Constants.SCHEMA_MAIN, systemUser, true);
...@@ -809,9 +809,9 @@ public class Database implements DataHandler { ...@@ -809,9 +809,9 @@ public class Database implements DataHandler {
} }
} }
systemSession.commit(true); systemSession.commit(true);
if (mvStore != null) { if (store != null) {
mvStore.getTransactionStore().endLeftoverTransactions(); store.getTransactionStore().endLeftoverTransactions();
mvStore.removeTemporaryMaps(objectIds); store.removeTemporaryMaps(objectIds);
} }
recompileInvalidViews(systemSession); recompileInvalidViews(systemSession);
starting = false; starting = false;
...@@ -1438,7 +1438,7 @@ public class Database implements DataHandler { ...@@ -1438,7 +1438,7 @@ public class Database implements DataHandler {
} }
boolean lobStorageIsUsed = infoSchema.findTableOrView( boolean lobStorageIsUsed = infoSchema.findTableOrView(
systemSession, LobStorageBackend.LOB_DATA_TABLE) != null; systemSession, LobStorageBackend.LOB_DATA_TABLE) != null;
lobStorageIsUsed |= mvStore != null; lobStorageIsUsed |= store != null;
if (!lobStorageIsUsed) { if (!lobStorageIsUsed) {
return; return;
} }
...@@ -1494,16 +1494,16 @@ public class Database implements DataHandler { ...@@ -1494,16 +1494,16 @@ public class Database implements DataHandler {
} }
} }
reconnectModified(false); reconnectModified(false);
if (mvStore != null && mvStore.getStore() != null && !mvStore.getStore().isClosed()) { if (store != null && store.getMvStore() != null && !store.getMvStore().isClosed()) {
long maxCompactTime = dbSettings.maxCompactTime; long maxCompactTime = dbSettings.maxCompactTime;
if (compactMode == CommandInterface.SHUTDOWN_COMPACT) { if (compactMode == CommandInterface.SHUTDOWN_COMPACT) {
mvStore.compactFile(dbSettings.maxCompactTime); store.compactFile(dbSettings.maxCompactTime);
} else if (compactMode == CommandInterface.SHUTDOWN_DEFRAG) { } else if (compactMode == CommandInterface.SHUTDOWN_DEFRAG) {
maxCompactTime = Long.MAX_VALUE; maxCompactTime = Long.MAX_VALUE;
} else if (getSettings().defragAlways) { } else if (getSettings().defragAlways) {
maxCompactTime = Long.MAX_VALUE; maxCompactTime = Long.MAX_VALUE;
} }
mvStore.close(maxCompactTime); store.close(maxCompactTime);
} }
if (systemSession != null) { if (systemSession != null) {
systemSession.close(); systemSession.close();
...@@ -1547,8 +1547,8 @@ public class Database implements DataHandler { ...@@ -1547,8 +1547,8 @@ public class Database implements DataHandler {
private synchronized void closeFiles() { private synchronized void closeFiles() {
try { try {
if (mvStore != null) { if (store != null) {
mvStore.closeImmediately(); store.closeImmediately();
} }
if (pageStore != null) { if (pageStore != null) {
pageStore.close(); pageStore.close();
...@@ -2028,8 +2028,8 @@ public class Database implements DataHandler { ...@@ -2028,8 +2028,8 @@ public class Database implements DataHandler {
if (pageStore != null) { if (pageStore != null) {
pageStore.getCache().setMaxMemory(kb); pageStore.getCache().setMaxMemory(kb);
} }
if (mvStore != null) { if (store != null) {
mvStore.setCacheSize(Math.max(1, kb)); store.setCacheSize(Math.max(1, kb));
} }
} }
...@@ -2090,9 +2090,9 @@ public class Database implements DataHandler { ...@@ -2090,9 +2090,9 @@ public class Database implements DataHandler {
// TODO check if MIN_WRITE_DELAY is a good value // TODO check if MIN_WRITE_DELAY is a good value
flushOnEachCommit = writeDelay < Constants.MIN_WRITE_DELAY; flushOnEachCommit = writeDelay < Constants.MIN_WRITE_DELAY;
} }
if (mvStore != null) { if (store != null) {
int millis = value < 0 ? 0 : value; int millis = value < 0 ? 0 : value;
mvStore.getStore().setAutoCommitDelay(millis); store.getMvStore().setAutoCommitDelay(millis);
} }
} }
...@@ -2102,8 +2102,8 @@ public class Database implements DataHandler { ...@@ -2102,8 +2102,8 @@ public class Database implements DataHandler {
public void setRetentionTime(int value) { public void setRetentionTime(int value) {
retentionTime = value; retentionTime = value;
if (mvStore != null) { if (store != null) {
mvStore.getStore().setRetentionTime(value); store.getMvStore().setRetentionTime(value);
} }
} }
...@@ -2130,8 +2130,8 @@ public class Database implements DataHandler { ...@@ -2130,8 +2130,8 @@ public class Database implements DataHandler {
* @return the list * @return the list
*/ */
public ArrayList<InDoubtTransaction> getInDoubtTransactions() { public ArrayList<InDoubtTransaction> getInDoubtTransactions() {
if (mvStore != null) { if (store != null) {
return mvStore.getInDoubtTransactions(); return store.getInDoubtTransactions();
} }
return pageStore == null ? null : pageStore.getInDoubtTransactions(); return pageStore == null ? null : pageStore.getInDoubtTransactions();
} }
...@@ -2146,8 +2146,8 @@ public class Database implements DataHandler { ...@@ -2146,8 +2146,8 @@ public class Database implements DataHandler {
if (readOnly) { if (readOnly) {
return; return;
} }
if (mvStore != null) { if (store != null) {
mvStore.prepareCommit(session, transaction); store.prepareCommit(session, transaction);
return; return;
} }
if (pageStore != null) { if (pageStore != null) {
...@@ -2190,7 +2190,7 @@ public class Database implements DataHandler { ...@@ -2190,7 +2190,7 @@ public class Database implements DataHandler {
} }
public Throwable getBackgroundException() { public Throwable getBackgroundException() {
IllegalStateException exception = mvStore.getStore().getPanicException(); IllegalStateException exception = store.getMvStore().getPanicException();
if(exception != null) { if(exception != null) {
return exception; return exception;
} }
...@@ -2208,9 +2208,9 @@ public class Database implements DataHandler { ...@@ -2208,9 +2208,9 @@ public class Database implements DataHandler {
if (pageStore != null) { if (pageStore != null) {
pageStore.flushLog(); pageStore.flushLog();
} }
if (mvStore != null) { if (store != null) {
try { try {
mvStore.flush(); store.flush();
} catch (RuntimeException e) { } catch (RuntimeException e) {
backgroundException.compareAndSet(null, DbException.convert(e)); backgroundException.compareAndSet(null, DbException.convert(e));
throw e; throw e;
...@@ -2286,8 +2286,8 @@ public class Database implements DataHandler { ...@@ -2286,8 +2286,8 @@ public class Database implements DataHandler {
if (readOnly) { if (readOnly) {
return; return;
} }
if (mvStore != null) { if (store != null) {
mvStore.sync(); store.sync();
} }
if (pageStore != null) { if (pageStore != null) {
pageStore.sync(); pageStore.sync();
...@@ -2614,8 +2614,8 @@ public class Database implements DataHandler { ...@@ -2614,8 +2614,8 @@ public class Database implements DataHandler {
public PageStore getPageStore() { public PageStore getPageStore() {
if (dbSettings.mvStore) { if (dbSettings.mvStore) {
if (mvStore == null) { if (store == null) {
mvStore = MVTableEngine.init(this); store = MVTableEngine.init(this);
} }
return null; return null;
} }
...@@ -2770,8 +2770,8 @@ public class Database implements DataHandler { ...@@ -2770,8 +2770,8 @@ public class Database implements DataHandler {
pageStore.checkpoint(); pageStore.checkpoint();
} }
} }
if (mvStore != null) { if (store != null) {
mvStore.flush(); store.flush();
} }
} }
getTempFileDeleter().deleteUnused(); getTempFileDeleter().deleteUnused();
...@@ -2890,7 +2890,7 @@ public class Database implements DataHandler { ...@@ -2890,7 +2890,7 @@ public class Database implements DataHandler {
this.logMode = log; this.logMode = log;
pageStore.setLogMode(log); pageStore.setLogMode(log);
} }
if (mvStore != null) { if (store != null) {
this.logMode = log; this.logMode = log;
} }
} }
...@@ -2899,7 +2899,7 @@ public class Database implements DataHandler { ...@@ -2899,7 +2899,7 @@ public class Database implements DataHandler {
if (pageStore != null) { if (pageStore != null) {
return pageStore.getLogMode(); return pageStore.getLogMode();
} }
if (mvStore != null) { if (store != null) {
return logMode; return logMode;
} }
return PageStore.LOG_MODE_OFF; return PageStore.LOG_MODE_OFF;
......
...@@ -735,7 +735,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba ...@@ -735,7 +735,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
private void endTransaction() { private void endTransaction() {
if (removeLobMap != null && removeLobMap.size() > 0) { if (removeLobMap != null && removeLobMap.size() > 0) {
if (database.getMvStore() == null) { if (database.getStore() == null) {
// need to flush the transaction log, because we can't unlink // need to flush the transaction log, because we can't unlink
// lobs if the commit record is not written // lobs if the commit record is not written
database.flush(); database.flush();
...@@ -826,7 +826,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba ...@@ -826,7 +826,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
if (undoLog != null) { if (undoLog != null) {
sp.logIndex = undoLog.size(); sp.logIndex = undoLog.size();
} }
if (database.getMvStore() != null) { if (database.getStore() != null) {
sp.transactionSavepoint = getStatementSavepoint(); sp.transactionSavepoint = getStatementSavepoint();
} }
return sp; return sp;
...@@ -1072,7 +1072,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba ...@@ -1072,7 +1072,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
* @return true if yes * @return true if yes
*/ */
public boolean containsUncommitted() { public boolean containsUncommitted() {
if (database.getMvStore() != null) { if (database.getStore() != null) {
return transaction != null && transaction.hasChanges(); return transaction != null && transaction.hasChanges();
} }
return firstUncommittedLog != Session.LOG_WRITTEN; return firstUncommittedLog != Session.LOG_WRITTEN;
...@@ -1608,7 +1608,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba ...@@ -1608,7 +1608,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
} }
public Value getTransactionId() { public Value getTransactionId() {
if (database.getMvStore() != null) { if (database.getStore() != null) {
if (transaction == null || !transaction.hasChanges()) { if (transaction == null || !transaction.hasChanges()) {
return ValueNull.INSTANCE; return ValueNull.INSTANCE;
} }
...@@ -1644,9 +1644,9 @@ public class Session extends SessionWithState implements TransactionStore.Rollba ...@@ -1644,9 +1644,9 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
*/ */
public Transaction getTransaction() { public Transaction getTransaction() {
if (transaction == null) { if (transaction == null) {
MVTableEngine.Store store = database.getMvStore(); MVTableEngine.Store store = database.getStore();
if (store != null) { if (store != null) {
if (store.getStore().isClosed()) { if (store.getMvStore().isClosed()) {
Throwable backgroundException = database.getBackgroundException(); Throwable backgroundException = database.getBackgroundException();
database.shutdownImmediately(); database.shutdownImmediately();
throw DbException.get(ErrorCode.DATABASE_IS_CLOSED, backgroundException); throw DbException.get(ErrorCode.DATABASE_IS_CLOSED, backgroundException);
...@@ -1749,7 +1749,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba ...@@ -1749,7 +1749,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
VersionedValue restoredValue) { VersionedValue restoredValue) {
// Here we are relying on the fact that map which backs table's primary index // Here we are relying on the fact that map which backs table's primary index
// has the same name as the table itself // has the same name as the table itself
MVTableEngine.Store store = database.getMvStore(); MVTableEngine.Store store = database.getStore();
if(store != null) { if(store != null) {
MVTable table = store.getTable(map.getName()); MVTable table = store.getTable(map.getName());
if (table != null) { if (table != null) {
......
...@@ -102,7 +102,7 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex { ...@@ -102,7 +102,7 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
"Persistent index with id<0"); "Persistent index with id<0");
} }
MVTableEngine.init(session.getDatabase()); MVTableEngine.init(session.getDatabase());
store = session.getDatabase().getMvStore().getStore(); store = session.getDatabase().getStore().getMvStore();
// Called after CREATE SPATIAL INDEX or // Called after CREATE SPATIAL INDEX or
// by PageStore.addMeta // by PageStore.addMeta
treeMap = store.openMap(MAP_PREFIX + getId(), treeMap = store.openMap(MAP_PREFIX + getId(),
......
...@@ -163,7 +163,7 @@ public class DatabaseInfo implements DatabaseInfoMBean { ...@@ -163,7 +163,7 @@ public class DatabaseInfo implements DatabaseInfoMBean {
if (p != null) { if (p != null) {
return p.getWriteCount(); return p.getWriteCount();
} }
return database.getMvStore().getStore().getFileStore().getReadCount(); return database.getStore().getMvStore().getFileStore().getReadCount();
} }
@Override @Override
...@@ -175,7 +175,7 @@ public class DatabaseInfo implements DatabaseInfoMBean { ...@@ -175,7 +175,7 @@ public class DatabaseInfo implements DatabaseInfoMBean {
if (p != null) { if (p != null) {
return p.getReadCount(); return p.getReadCount();
} }
return database.getMvStore().getStore().getFileStore().getReadCount(); return database.getStore().getMvStore().getFileStore().getReadCount();
} }
@Override @Override
...@@ -187,7 +187,7 @@ public class DatabaseInfo implements DatabaseInfoMBean { ...@@ -187,7 +187,7 @@ public class DatabaseInfo implements DatabaseInfoMBean {
if (p != null) { if (p != null) {
return p.getPageCount() * p.getPageSize() / 1024; return p.getPageCount() * p.getPageSize() / 1024;
} }
return database.getMvStore().getStore().getFileStore().size(); return database.getStore().getMvStore().getFileStore().size();
} }
@Override @Override
...@@ -199,7 +199,7 @@ public class DatabaseInfo implements DatabaseInfoMBean { ...@@ -199,7 +199,7 @@ public class DatabaseInfo implements DatabaseInfoMBean {
if (p != null) { if (p != null) {
return p.getCache().getMaxMemory(); return p.getCache().getMaxMemory();
} }
return database.getMvStore().getStore().getCacheSize() * 1024; return database.getStore().getMvStore().getCacheSize() * 1024;
} }
@Override @Override
...@@ -218,7 +218,7 @@ public class DatabaseInfo implements DatabaseInfoMBean { ...@@ -218,7 +218,7 @@ public class DatabaseInfo implements DatabaseInfoMBean {
if (p != null) { if (p != null) {
return p.getCache().getMemory(); return p.getCache().getMemory();
} }
return database.getMvStore().getStore().getCacheSizeUsed() * 1024; return database.getStore().getMvStore().getCacheSizeUsed() * 1024;
} }
@Override @Override
......
...@@ -148,9 +148,9 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex { ...@@ -148,9 +148,9 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
} }
} }
} finally { } finally {
MVStore store = database.getMvStore().getStore(); MVStore mvStore = database.getStore().getMvStore();
for (String tempMapName : bufferNames) { for (String tempMapName : bufferNames) {
store.removeMap(tempMapName); mvStore.removeMap(tempMapName);
} }
} }
} }
...@@ -167,8 +167,8 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex { ...@@ -167,8 +167,8 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
new MVMap.Builder<ValueArray, Value>() new MVMap.Builder<ValueArray, Value>()
.singleWriter() .singleWriter()
.keyType(keyType).valueType(valueType); .keyType(keyType).valueType(valueType);
MVMap<ValueArray, Value> map = database.getMvStore(). MVMap<ValueArray, Value> map = database.getStore().
getStore().openMap(mapName, builder); getMvStore().openMap(mapName, builder);
if (!keyType.equals(map.getKeyType())) { if (!keyType.equals(map.getKeyType())) {
throw DbException.throwInternalError( throw DbException.throwInternalError(
"Incompatible key type, expected " + keyType + " but got " "Incompatible key type, expected " + keyType + " but got "
......
...@@ -98,7 +98,7 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex { ...@@ -98,7 +98,7 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
MVRTreeMap.Builder<VersionedValue> mapBuilder = MVRTreeMap.Builder<VersionedValue> mapBuilder =
new MVRTreeMap.Builder<VersionedValue>(). new MVRTreeMap.Builder<VersionedValue>().
valueType(valueType); valueType(valueType);
spatialMap = db.getMvStore().getStore().openMap(mapName, mapBuilder); spatialMap = db.getStore().getMvStore().openMap(mapName, mapBuilder);
Transaction t = mvTable.getTransactionBegin(); Transaction t = mvTable.getTransactionBegin();
dataMap = t.openMap(spatialMap); dataMap = t.openMap(spatialMap);
dataMap.map.setVolatile(!table.isPersistData() || !indexType.isPersistent()); dataMap.map.setVolatile(!table.isPersistData() || !indexType.isPersistent());
......
...@@ -538,7 +538,7 @@ public class MVTable extends TableBase { ...@@ -538,7 +538,7 @@ public class MVTable extends TableBase {
private void rebuildIndex(Session session, MVIndex index, String indexName) { private void rebuildIndex(Session session, MVIndex index, String indexName) {
try { try {
if (session.getDatabase().getMvStore() == null || if (session.getDatabase().getStore() == null ||
index instanceof MVSpatialIndex) { index instanceof MVSpatialIndex) {
// in-memory // in-memory
rebuildIndexBuffered(session, index); rebuildIndexBuffered(session, index);
...@@ -577,7 +577,7 @@ public class MVTable extends TableBase { ...@@ -577,7 +577,7 @@ public class MVTable extends TableBase {
long total = remaining; long total = remaining;
Cursor cursor = scan.find(session, null, null); Cursor cursor = scan.find(session, null, null);
long i = 0; long i = 0;
Store store = session.getDatabase().getMvStore(); Store store = session.getDatabase().getStore();
int bufferSize = database.getMaxMemoryRows() / 2; int bufferSize = database.getMaxMemoryRows() / 2;
ArrayList<Row> buffer = new ArrayList<>(bufferSize); ArrayList<Row> buffer = new ArrayList<>(bufferSize);
...@@ -807,7 +807,7 @@ public class MVTable extends TableBase { ...@@ -807,7 +807,7 @@ public class MVTable extends TableBase {
database.getLobStorage().removeAllForTable(getId()); database.getLobStorage().removeAllForTable(getId());
database.lockMeta(session); database.lockMeta(session);
} }
database.getMvStore().removeTable(this); database.getStore().removeTable(this);
super.removeChildrenAndResources(session); super.removeChildrenAndResources(session);
// go backwards because database.removeIndex will // go backwards because database.removeIndex will
// call table.removeIndex // call table.removeIndex
......
...@@ -47,7 +47,7 @@ public class MVTableEngine implements TableEngine { ...@@ -47,7 +47,7 @@ public class MVTableEngine implements TableEngine {
* @return the store * @return the store
*/ */
public static Store init(final Database db) { public static Store init(final Database db) {
Store store = db.getMvStore(); Store store = db.getStore();
if (store != null) { if (store != null) {
return store; return store;
} }
...@@ -92,7 +92,7 @@ public class MVTableEngine implements TableEngine { ...@@ -92,7 +92,7 @@ public class MVTableEngine implements TableEngine {
}); });
} }
store.open(db, builder, encrypted); store.open(db, builder, encrypted);
db.setMvStore(store); db.setStore(store);
return store; return store;
} }
...@@ -127,7 +127,7 @@ public class MVTableEngine implements TableEngine { ...@@ -127,7 +127,7 @@ public class MVTableEngine implements TableEngine {
/** /**
* The store. * The store.
*/ */
private MVStore store; private MVStore mvStore;
/** /**
* The transaction store. * The transaction store.
...@@ -152,15 +152,15 @@ public class MVTableEngine implements TableEngine { ...@@ -152,15 +152,15 @@ public class MVTableEngine implements TableEngine {
void open(Database db, MVStore.Builder builder, boolean encrypted) { void open(Database db, MVStore.Builder builder, boolean encrypted) {
this.encrypted = encrypted; this.encrypted = encrypted;
try { try {
this.store = builder.open(); this.mvStore = builder.open();
FileStore fs = store.getFileStore(); FileStore fs = mvStore.getFileStore();
if (fs != null) { if (fs != null) {
this.fileName = fs.getFileName(); this.fileName = fs.getFileName();
} }
if (!db.getSettings().reuseSpace) { if (!db.getSettings().reuseSpace) {
store.setReuseSpace(false); mvStore.setReuseSpace(false);
} }
this.transactionStore = new TransactionStore(store, this.transactionStore = new TransactionStore(mvStore,
new ValueDataType(db, null), db.getLockTimeout()); new ValueDataType(db, null), db.getLockTimeout());
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
throw convertIllegalStateException(e); throw convertIllegalStateException(e);
...@@ -201,8 +201,8 @@ public class MVTableEngine implements TableEngine { ...@@ -201,8 +201,8 @@ public class MVTableEngine implements TableEngine {
} }
public MVStore getStore() { public MVStore getMvStore() {
return store; return mvStore;
} }
public TransactionStore getTransactionStore() { public TransactionStore getTransactionStore() {
...@@ -238,12 +238,12 @@ public class MVTableEngine implements TableEngine { ...@@ -238,12 +238,12 @@ public class MVTableEngine implements TableEngine {
* Store all pending changes. * Store all pending changes.
*/ */
public void flush() { public void flush() {
FileStore s = store.getFileStore(); FileStore s = mvStore.getFileStore();
if (s == null || s.isReadOnly()) { if (s == null || s.isReadOnly()) {
return; return;
} }
if (!store.compact(50, 4 * 1024 * 1024)) { if (!mvStore.compact(50, 4 * 1024 * 1024)) {
store.commit(); mvStore.commit();
} }
} }
...@@ -251,10 +251,10 @@ public class MVTableEngine implements TableEngine { ...@@ -251,10 +251,10 @@ public class MVTableEngine implements TableEngine {
* Close the store, without persisting changes. * Close the store, without persisting changes.
*/ */
public void closeImmediately() { public void closeImmediately() {
if (store.isClosed()) { if (mvStore.isClosed()) {
return; return;
} }
store.closeImmediately(); mvStore.closeImmediately();
} }
/** /**
...@@ -263,13 +263,13 @@ public class MVTableEngine implements TableEngine { ...@@ -263,13 +263,13 @@ public class MVTableEngine implements TableEngine {
* @param objectIds the ids of the objects to keep * @param objectIds the ids of the objects to keep
*/ */
public void removeTemporaryMaps(BitSet objectIds) { public void removeTemporaryMaps(BitSet objectIds) {
for (String mapName : store.getMapNames()) { for (String mapName : mvStore.getMapNames()) {
if (mapName.startsWith("temp.")) { if (mapName.startsWith("temp.")) {
store.removeMap(mapName); mvStore.removeMap(mapName);
} else if (mapName.startsWith("table.") || mapName.startsWith("index.")) { } else if (mapName.startsWith("table.") || mapName.startsWith("index.")) {
int id = Integer.parseInt(mapName.substring(1 + mapName.indexOf('.'))); int id = Integer.parseInt(mapName.substring(1 + mapName.indexOf('.')));
if (!objectIds.get(id)) { if (!objectIds.get(id)) {
store.removeMap(mapName); mvStore.removeMap(mapName);
} }
} }
} }
...@@ -294,7 +294,7 @@ public class MVTableEngine implements TableEngine { ...@@ -294,7 +294,7 @@ public class MVTableEngine implements TableEngine {
Transaction t = session.getTransaction(); Transaction t = session.getTransaction();
t.setName(transactionName); t.setName(transactionName);
t.prepare(); t.prepare();
store.commit(); mvStore.commit();
} }
public ArrayList<InDoubtTransaction> getInDoubtTransactions() { public ArrayList<InDoubtTransaction> getInDoubtTransactions() {
...@@ -302,7 +302,7 @@ public class MVTableEngine implements TableEngine { ...@@ -302,7 +302,7 @@ public class MVTableEngine implements TableEngine {
ArrayList<InDoubtTransaction> result = Utils.newSmallArrayList(); ArrayList<InDoubtTransaction> result = Utils.newSmallArrayList();
for (Transaction t : list) { for (Transaction t : list) {
if (t.getStatus() == Transaction.STATUS_PREPARED) { if (t.getStatus() == Transaction.STATUS_PREPARED) {
result.add(new MVInDoubtTransaction(store, t)); result.add(new MVInDoubtTransaction(mvStore, t));
} }
} }
return result; return result;
...@@ -314,13 +314,13 @@ public class MVTableEngine implements TableEngine { ...@@ -314,13 +314,13 @@ public class MVTableEngine implements TableEngine {
* @param kb the maximum size in KB * @param kb the maximum size in KB
*/ */
public void setCacheSize(int kb) { public void setCacheSize(int kb) {
store.setCacheSize(Math.max(1, kb / 1024)); mvStore.setCacheSize(Math.max(1, kb / 1024));
} }
public InputStream getInputStream() { public InputStream getInputStream() {
FileChannel fc = store.getFileStore().getEncryptedFile(); FileChannel fc = mvStore.getFileStore().getEncryptedFile();
if (fc == null) { if (fc == null) {
fc = store.getFileStore().getFile(); fc = mvStore.getFileStore().getFile();
} }
return new FileChannelInputStream(fc, false); return new FileChannelInputStream(fc, false);
} }
...@@ -330,7 +330,7 @@ public class MVTableEngine implements TableEngine { ...@@ -330,7 +330,7 @@ public class MVTableEngine implements TableEngine {
*/ */
public void sync() { public void sync() {
flush(); flush();
store.sync(); mvStore.sync();
} }
/** /**
...@@ -342,11 +342,11 @@ public class MVTableEngine implements TableEngine { ...@@ -342,11 +342,11 @@ public class MVTableEngine implements TableEngine {
* @param maxCompactTime the maximum time in milliseconds to compact * @param maxCompactTime the maximum time in milliseconds to compact
*/ */
public void compactFile(long maxCompactTime) { public void compactFile(long maxCompactTime) {
store.setRetentionTime(0); mvStore.setRetentionTime(0);
long start = System.nanoTime(); long start = System.nanoTime();
while (store.compact(95, 16 * 1024 * 1024)) { while (mvStore.compact(95, 16 * 1024 * 1024)) {
store.sync(); mvStore.sync();
store.compactMoveChunks(95, 16 * 1024 * 1024); mvStore.compactMoveChunks(95, 16 * 1024 * 1024);
long time = System.nanoTime() - start; long time = System.nanoTime() - start;
if (time > TimeUnit.MILLISECONDS.toNanos(maxCompactTime)) { if (time > TimeUnit.MILLISECONDS.toNanos(maxCompactTime)) {
break; break;
...@@ -363,16 +363,16 @@ public class MVTableEngine implements TableEngine { ...@@ -363,16 +363,16 @@ public class MVTableEngine implements TableEngine {
*/ */
public void close(long maxCompactTime) { public void close(long maxCompactTime) {
try { try {
if (!store.isClosed() && store.getFileStore() != null) { if (!mvStore.isClosed() && mvStore.getFileStore() != null) {
boolean compactFully = false; boolean compactFully = false;
if (!store.getFileStore().isReadOnly()) { if (!mvStore.getFileStore().isReadOnly()) {
transactionStore.close(); transactionStore.close();
if (maxCompactTime == Long.MAX_VALUE) { if (maxCompactTime == Long.MAX_VALUE) {
compactFully = true; compactFully = true;
} }
} }
String fileName = store.getFileStore().getFileName(); String fileName = mvStore.getFileStore().getFileName();
store.close(); mvStore.close();
if (compactFully && FileUtils.exists(fileName)) { if (compactFully && FileUtils.exists(fileName)) {
// the file could have been deleted concurrently, // the file could have been deleted concurrently,
// so only compact if the file still exists // so only compact if the file still exists
...@@ -386,7 +386,7 @@ public class MVTableEngine implements TableEngine { ...@@ -386,7 +386,7 @@ public class MVTableEngine implements TableEngine {
} else if (errorCode == DataUtils.ERROR_FILE_CORRUPT) { } else if (errorCode == DataUtils.ERROR_FILE_CORRUPT) {
// wrong encryption key - ok // wrong encryption key - ok
} }
store.closeImmediately(); mvStore.closeImmediately();
throw DbException.get(ErrorCode.IO_EXCEPTION_1, e, "Closing"); throw DbException.get(ErrorCode.IO_EXCEPTION_1, e, "Closing");
} }
} }
...@@ -395,7 +395,7 @@ public class MVTableEngine implements TableEngine { ...@@ -395,7 +395,7 @@ public class MVTableEngine implements TableEngine {
* Start collecting statistics. * Start collecting statistics.
*/ */
public void statisticsStart() { public void statisticsStart() {
FileStore fs = store.getFileStore(); FileStore fs = mvStore.getFileStore();
statisticsStart = fs == null ? 0 : fs.getReadCount(); statisticsStart = fs == null ? 0 : fs.getReadCount();
} }
...@@ -406,7 +406,7 @@ public class MVTableEngine implements TableEngine { ...@@ -406,7 +406,7 @@ public class MVTableEngine implements TableEngine {
*/ */
public Map<String, Integer> statisticsEnd() { public Map<String, Integer> statisticsEnd() {
HashMap<String, Integer> map = new HashMap<>(); HashMap<String, Integer> map = new HashMap<>();
FileStore fs = store.getFileStore(); FileStore fs = mvStore.getFileStore();
int reads = fs == null ? 0 : (int) (fs.getReadCount() - statisticsStart); int reads = fs == null ? 0 : (int) (fs.getReadCount() - statisticsStart);
map.put("reads", reads); map.put("reads", reads);
return map; return map;
......
...@@ -72,13 +72,13 @@ public class LobStorageMap implements LobStorageInterface { ...@@ -72,13 +72,13 @@ public class LobStorageMap implements LobStorageInterface {
return; return;
} }
init = true; init = true;
Store s = database.getMvStore(); Store s = database.getStore();
MVStore mvStore; MVStore mvStore;
if (s == null) { if (s == null) {
// in-memory database // in-memory database
mvStore = MVStore.open(null); mvStore = MVStore.open(null);
} else { } else {
mvStore = s.getStore(); mvStore = s.getMvStore();
} }
lobMap = mvStore.openMap("lobMap"); lobMap = mvStore.openMap("lobMap");
refMap = mvStore.openMap("lobRef"); refMap = mvStore.openMap("lobRef");
...@@ -289,7 +289,7 @@ public class LobStorageMap implements LobStorageInterface { ...@@ -289,7 +289,7 @@ public class LobStorageMap implements LobStorageInterface {
@Override @Override
public void removeAllForTable(int tableId) { public void removeAllForTable(int tableId) {
init(); init();
if (database.getMvStore().getStore().isClosed()) { if (database.getStore().getMvStore().isClosed()) {
return; return;
} }
// this might not be very efficient - // this might not be very efficient -
......
...@@ -45,6 +45,7 @@ import org.h2.index.MetaIndex; ...@@ -45,6 +45,7 @@ import org.h2.index.MetaIndex;
import org.h2.jdbc.JdbcSQLException; import org.h2.jdbc.JdbcSQLException;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.mvstore.FileStore; import org.h2.mvstore.FileStore;
import org.h2.mvstore.MVStore;
import org.h2.mvstore.db.MVTableEngine.Store; import org.h2.mvstore.db.MVTableEngine.Store;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.result.SearchRow; import org.h2.result.SearchRow;
...@@ -1051,32 +1052,33 @@ public class MetaTable extends Table { ...@@ -1051,32 +1052,33 @@ public class MetaTable extends Table {
add(rows, k, s.get(k)); add(rows, k, s.get(k));
} }
if (database.isPersistent()) { if (database.isPersistent()) {
PageStore store = database.getPageStore(); PageStore pageStore = database.getPageStore();
if (store != null) { if (pageStore != null) {
add(rows, "info.FILE_WRITE_TOTAL", add(rows, "info.FILE_WRITE_TOTAL",
Long.toString(store.getWriteCountTotal())); Long.toString(pageStore.getWriteCountTotal()));
add(rows, "info.FILE_WRITE", add(rows, "info.FILE_WRITE",
Long.toString(store.getWriteCount())); Long.toString(pageStore.getWriteCount()));
add(rows, "info.FILE_READ", add(rows, "info.FILE_READ",
Long.toString(store.getReadCount())); Long.toString(pageStore.getReadCount()));
add(rows, "info.PAGE_COUNT", add(rows, "info.PAGE_COUNT",
Integer.toString(store.getPageCount())); Integer.toString(pageStore.getPageCount()));
add(rows, "info.PAGE_SIZE", add(rows, "info.PAGE_SIZE",
Integer.toString(store.getPageSize())); Integer.toString(pageStore.getPageSize()));
add(rows, "info.CACHE_MAX_SIZE", add(rows, "info.CACHE_MAX_SIZE",
Integer.toString(store.getCache().getMaxMemory())); Integer.toString(pageStore.getCache().getMaxMemory()));
add(rows, "info.CACHE_SIZE", add(rows, "info.CACHE_SIZE",
Integer.toString(store.getCache().getMemory())); Integer.toString(pageStore.getCache().getMemory()));
} }
Store mvStore = database.getMvStore(); Store store = database.getStore();
if (mvStore != null) { if (store != null) {
FileStore fs = mvStore.getStore().getFileStore(); MVStore mvStore = store.getMvStore();
FileStore fs = mvStore.getFileStore();
add(rows, "info.FILE_WRITE", add(rows, "info.FILE_WRITE",
Long.toString(fs.getWriteCount())); Long.toString(fs.getWriteCount()));
add(rows, "info.FILE_READ", add(rows, "info.FILE_READ",
Long.toString(fs.getReadCount())); Long.toString(fs.getReadCount()));
add(rows, "info.UPDATE_FAILURE_PERCENT", add(rows, "info.UPDATE_FAILURE_PERCENT",
String.format(Locale.ENGLISH, "%.2f%%", 100 * mvStore.getStore().getUpdateFailureRatio())); String.format(Locale.ENGLISH, "%.2f%%", 100 * mvStore.getUpdateFailureRatio()));
long size; long size;
try { try {
size = fs.getFile().size(); size = fs.getFile().size();
...@@ -1090,9 +1092,9 @@ public class MetaTable extends Table { ...@@ -1090,9 +1092,9 @@ public class MetaTable extends Table {
add(rows, "info.PAGE_SIZE", add(rows, "info.PAGE_SIZE",
Integer.toString(pageSize)); Integer.toString(pageSize));
add(rows, "info.CACHE_MAX_SIZE", add(rows, "info.CACHE_MAX_SIZE",
Integer.toString(mvStore.getStore().getCacheSize())); Integer.toString(mvStore.getCacheSize()));
add(rows, "info.CACHE_SIZE", add(rows, "info.CACHE_SIZE",
Integer.toString(mvStore.getStore().getCacheSizeUsed())); Integer.toString(mvStore.getCacheSizeUsed()));
} }
} }
break; break;
......
...@@ -1130,7 +1130,7 @@ public class TestMVTableEngine extends TestDb { ...@@ -1130,7 +1130,7 @@ public class TestMVTableEngine extends TestDb {
conn = getConnection(dbName); conn = getConnection(dbName);
Database db = (Database) ((JdbcConnection) conn).getSession() Database db = (Database) ((JdbcConnection) conn).getSession()
.getDataHandler(); .getDataHandler();
assertTrue(db.getMvStore().getStore().getFileStore().isReadOnly()); assertTrue(db.getStore().getMvStore().getFileStore().isReadOnly());
conn.close(); conn.close();
} }
...@@ -1144,7 +1144,7 @@ public class TestMVTableEngine extends TestDb { ...@@ -1144,7 +1144,7 @@ public class TestMVTableEngine extends TestDb {
conn = getConnection(dbName); conn = getConnection(dbName);
Database db = (Database) ((JdbcConnection) conn). Database db = (Database) ((JdbcConnection) conn).
getSession().getDataHandler(); getSession().getDataHandler();
db.getMvStore().getStore().setRetentionTime(0); db.getStore().getMvStore().setRetentionTime(0);
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("create table test(id int primary key, data varchar)"); stat.execute("create table test(id int primary key, data varchar)");
stat.execute("insert into test select x, space(1000) " + stat.execute("insert into test select x, space(1000) " +
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论