1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2002,2010 Oracle. All rights reserved.
*
* $Id: SR10597Test.java,v 1.10.2.2 2010/01/04 15:30:42 cwl Exp $
*/
package com.sleepycat.je.cleaner;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import com.sleepycat.je.CheckpointConfig;
import com.sleepycat.je.Cursor;
import com.sleepycat.je.Database;
import com.sleepycat.je.DatabaseConfig;
import com.sleepycat.je.DatabaseEntry;
import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.DbInternal;
import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig;
import com.sleepycat.je.OperationStatus;
import com.sleepycat.je.config.EnvironmentParams;
import com.sleepycat.je.log.FileManager;
import com.sleepycat.je.util.TestUtils;
public class SR10597Test extends TestCase {
private static final String DB_NAME = "foo";
private static final CheckpointConfig forceConfig = new CheckpointConfig();
static {
forceConfig.setForce(true);
}
private File envHome;
private Environment env;
private Database db;
public SR10597Test() {
envHome = new File(System.getProperty(TestUtils.DEST_DIR));
}
public void setUp()
throws IOException, DatabaseException {
TestUtils.removeLogFiles("Setup", envHome, false);
TestUtils.removeFiles("Setup", envHome, FileManager.DEL_SUFFIX);
}
public void tearDown()
throws IOException, DatabaseException {
try {
if (env != null) {
env.close();
}
} catch (Throwable e) {
System.out.println("tearDown: " + e);
}
try {
TestUtils.removeLogFiles("tearDown", envHome, true);
TestUtils.removeFiles("tearDown", envHome, FileManager.DEL_SUFFIX);
} catch (Throwable e) {
System.out.println("tearDown: " + e);
}
db = null;
env = null;
envHome = null;
}
/**
* Opens the environment and database.
*/
private void openEnv()
throws DatabaseException {
EnvironmentConfig config = TestUtils.initEnvConfig();
DbInternal.disableParameterValidation(config);
config.setAllowCreate(true);
/* Do not run the daemons. */
config.setConfigParam
(EnvironmentParams.ENV_RUN_CLEANER.getName(), "false");
config.setConfigParam
(EnvironmentParams.ENV_RUN_EVICTOR.getName(), "false");
config.setConfigParam
(EnvironmentParams.ENV_RUN_CHECKPOINTER.getName(), "false");
config.setConfigParam
(EnvironmentParams.ENV_RUN_INCOMPRESSOR.getName(), "false");
/* Use a small log file size to make cleaning more frequent. */
config.setConfigParam(EnvironmentParams.LOG_FILE_MAX.getName(),
Integer.toString(1024));
env = new Environment(envHome, config);
openDb();
}
/**
* Opens that database.
*/
private void openDb()
throws DatabaseException {
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setAllowCreate(true);
dbConfig.setSortedDuplicates(true);
db = env.openDatabase(null, DB_NAME, dbConfig);
}
/**
* Closes the environment and database.
*/
private void closeEnv()
throws DatabaseException {
if (db != null) {
db.close();
db = null;
}
if (env != null) {
env.close();
env = null;
}
}
/**
*/
public void testSR10597()
throws DatabaseException {
openEnv();
/* Put some duplicates, enough to fill a log file. */
final int COUNT = 10;
DatabaseEntry key = new DatabaseEntry(TestUtils.getTestArray(0));
DatabaseEntry data = new DatabaseEntry();
for (int i = 0; i < COUNT; i += 1) {
data.setData(TestUtils.getTestArray(i));
db.put(null, key, data);
}
Cursor cursor = db.openCursor(null, null);
assertEquals(OperationStatus.SUCCESS,
cursor.getSearchKey(key, data, null));
assertEquals(COUNT, cursor.count());
cursor.close();
/* Delete everything, then compress to delete the DIN. */
db.delete(null, key);
env.compress();
data.setData(TestUtils.getTestArray(0));
/* Add a single record, which will not create a DIN. */
db.put(null, key, data);
/* Checkpoint and clean. */
env.checkpoint(forceConfig);
int cleaned = env.cleanLog();
assertTrue("cleaned=" + cleaned, cleaned > 0);
/*
* Before the fix to 10597, when cleaning the log we would be looking
* for an LN with containsDuplicates=true. We assumed that when we
* found the BIN entry, it must point to a DIN. But because we
* deleted and compressed above, the entry is actually an LN. This
* caused a ClassCastException at the bottom of
* Tree.getParentBINForChildLN.
*/
closeEnv();
}
}
|