提交 898d8915 authored 作者: Thomas Mueller's avatar Thomas Mueller

A database could not be opened sometimes after dropping tables or indexes, and…

A database could not be opened sometimes after dropping tables or indexes, and then creating new indexes for existing tables.
上级 2ffb4adb
......@@ -18,7 +18,10 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>-
<ul><li>In versions 1.2.129 and 1.2.130, a database could not be opened sometimes
after dropping tables or indexes, and then creating new indexes for existing tables.
The exception contained the text "Table not found".
</li><li>After the database was closed, a null pointer exception could occur in Database.flush.
</li></ul>
<h2>Version 1.2.130 (2010-02-26)</h2>
......
......@@ -139,7 +139,7 @@ public class PageStore implements CacheWriter {
private static final int READ_VERSION = 3;
private static final int WRITE_VERSION = 3;
private static final int META_TYPE_SCAN_INDEX = 0;
private static final int META_TYPE_DATA_INDEX = 0;
private static final int META_TYPE_BTREE_INDEX = 1;
private static final int META_TABLE_ID = -1;
......@@ -1231,9 +1231,23 @@ public class PageStore implements CacheWriter {
private void readMetaData() {
Cursor cursor = metaIndex.find(systemSession, null, null);
// first, create all tables
while (cursor.next()) {
Row row = cursor.get();
addMeta(row, systemSession, false);
int type = row.getValue(1).getInt();
if (type == META_TYPE_DATA_INDEX) {
addMeta(row, systemSession, false);
}
}
// now create all secondary indexes
// otherwise the table might not be created yet
cursor = metaIndex.find(systemSession, null, null);
while (cursor.next()) {
Row row = cursor.get();
int type = row.getValue(1).getInt();
if (type != META_TYPE_DATA_INDEX) {
addMeta(row, systemSession, false);
}
}
}
......@@ -1281,7 +1295,7 @@ public class PageStore implements CacheWriter {
allocatePage(rootPageId);
}
metaRootPageId.put(id, rootPageId);
if (type == META_TYPE_SCAN_INDEX) {
if (type == META_TYPE_DATA_INDEX) {
CreateTableData data = new CreateTableData();
for (int i = 0; i < columns.length; i++) {
Column col = new Column("C" + i, Value.INT);
......@@ -1357,7 +1371,7 @@ public class PageStore implements CacheWriter {
* @param session the session
*/
public void addMeta(PageIndex index, Session session) {
int type = index instanceof PageDataIndex ? META_TYPE_SCAN_INDEX : META_TYPE_BTREE_INDEX;
int type = index instanceof PageDataIndex ? META_TYPE_DATA_INDEX : META_TYPE_BTREE_INDEX;
IndexColumn[] columns = index.getIndexColumns();
StatementBuilder buff = new StatementBuilder();
for (IndexColumn col : columns) {
......
......@@ -35,6 +35,7 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
}
public void test() throws Exception {
testDropRecreate();
testDropAll();
testCloseTempTable();
testDuplicateKey();
......@@ -57,6 +58,26 @@ public class TestPageStore extends TestBase implements DatabaseEventListener {
testFuzzOperations();
}
private void testDropRecreate() throws SQLException {
if (config.memory) {
return;
}
deleteDb("pageStore");
Connection conn;
conn = getConnection("pageStore");
Statement stat = conn.createStatement();
stat.execute("create table test(id int)");
stat.execute("create index idx_test on test(id)");
stat.execute("create table test2(id int)");
stat.execute("drop table test");
// this will re-used the object id of the test table,
// which is lower than the object id of test2
stat.execute("create index idx_test on test2(id)");
conn.close();
conn = getConnection("pageStore");
conn.close();
}
private void testDropAll() throws SQLException {
deleteDb("pageStore");
Connection conn;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论