PageRenderTime 67ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/simpledbm-rss/code/simpledbm-rss/src/test/java/org/simpledbm/rss/impl/im/btree/TestBTreeManager.java

https://code.google.com/p/simpledbm/
Java | 3999 lines | 3275 code | 283 blank | 441 comment | 249 complexity | 1a67f4013060108c5770fd6e0fe78476 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. /***
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. *
  16. * Linking this library statically or dynamically with other modules
  17. * is making a combined work based on this library. Thus, the terms and
  18. * conditions of the GNU General Public License cover the whole
  19. * combination.
  20. *
  21. * As a special exception, the copyright holders of this library give
  22. * you permission to link this library with independent modules to
  23. * produce an executable, regardless of the license terms of these
  24. * independent modules, and to copy and distribute the resulting
  25. * executable under terms of your choice, provided that you also meet,
  26. * for each linked independent module, the terms and conditions of the
  27. * license of that module. An independent module is a module which
  28. * is not derived from or based on this library. If you modify this
  29. * library, you may extend this exception to your version of the
  30. * library, but you are not obligated to do so. If you do not wish
  31. * to do so, delete this exception statement from your version.
  32. *
  33. * Project: www.simpledbm.org
  34. * Author : Dibyendu Majumdar
  35. * Email : d dot majumdar at gmail dot com ignore
  36. */
  37. package org.simpledbm.rss.impl.im.btree;
  38. import java.io.BufferedReader;
  39. import java.io.InputStreamReader;
  40. import java.nio.ByteBuffer;
  41. import java.util.Arrays;
  42. import java.util.Properties;
  43. import java.util.StringTokenizer;
  44. import java.util.concurrent.TimeUnit;
  45. import java.util.concurrent.atomic.AtomicInteger;
  46. import java.util.concurrent.locks.Condition;
  47. import java.util.concurrent.locks.Lock;
  48. import java.util.concurrent.locks.ReentrantLock;
  49. import junit.framework.Test;
  50. import junit.framework.TestSuite;
  51. import org.simpledbm.common.api.exception.SimpleDBMException;
  52. import org.simpledbm.common.api.key.IndexKey;
  53. import org.simpledbm.common.api.key.IndexKeyFactory;
  54. import org.simpledbm.common.api.locking.LockMode;
  55. import org.simpledbm.common.api.platform.Platform;
  56. import org.simpledbm.common.api.platform.PlatformObjects;
  57. import org.simpledbm.common.api.registry.ObjectRegistry;
  58. import org.simpledbm.common.api.tx.IsolationMode;
  59. import org.simpledbm.common.impl.registry.ObjectRegistryImpl;
  60. import org.simpledbm.common.tools.diagnostics.TraceBuffer;
  61. import org.simpledbm.common.util.ByteString;
  62. import org.simpledbm.junit.BaseTestCase;
  63. import org.simpledbm.rss.api.bm.BufferAccessBlock;
  64. import org.simpledbm.rss.api.fsm.FreeSpaceManager;
  65. import org.simpledbm.rss.api.im.IndexContainer;
  66. import org.simpledbm.rss.api.im.IndexManager;
  67. import org.simpledbm.rss.api.im.IndexScan;
  68. import org.simpledbm.rss.api.im.UniqueConstraintViolationException;
  69. import org.simpledbm.rss.api.latch.LatchFactory;
  70. import org.simpledbm.rss.api.loc.Location;
  71. import org.simpledbm.rss.api.loc.LocationFactory;
  72. import org.simpledbm.rss.api.locking.LockDeadlockException;
  73. import org.simpledbm.rss.api.locking.LockDuration;
  74. import org.simpledbm.rss.api.locking.LockMgrFactory;
  75. import org.simpledbm.rss.api.locking.util.LockAdaptor;
  76. import org.simpledbm.rss.api.pm.Page;
  77. import org.simpledbm.rss.api.pm.PageId;
  78. import org.simpledbm.rss.api.pm.PageManager;
  79. import org.simpledbm.rss.api.sp.SlottedPage;
  80. import org.simpledbm.rss.api.sp.SlottedPageManager;
  81. import org.simpledbm.rss.api.st.StorageContainer;
  82. import org.simpledbm.rss.api.st.StorageContainerFactory;
  83. import org.simpledbm.rss.api.st.StorageManager;
  84. import org.simpledbm.rss.api.tx.BaseLockable;
  85. import org.simpledbm.rss.api.tx.LoggableFactory;
  86. import org.simpledbm.rss.api.tx.Savepoint;
  87. import org.simpledbm.rss.api.tx.Transaction;
  88. import org.simpledbm.rss.api.tx.TransactionalModuleRegistry;
  89. import org.simpledbm.rss.api.wal.Lsn;
  90. import org.simpledbm.rss.impl.bm.BufferManagerImpl;
  91. import org.simpledbm.rss.impl.fsm.FreeSpaceManagerImpl;
  92. import org.simpledbm.rss.impl.im.btree.BTreeIndexManagerImpl.BTreeContext;
  93. import org.simpledbm.rss.impl.im.btree.BTreeIndexManagerImpl.BTreeImpl;
  94. import org.simpledbm.rss.impl.im.btree.BTreeIndexManagerImpl.BTreeNode;
  95. import org.simpledbm.rss.impl.im.btree.BTreeIndexManagerImpl.IndexItem;
  96. import org.simpledbm.rss.impl.im.btree.BTreeIndexManagerImpl.IndexItemFactory;
  97. import org.simpledbm.rss.impl.im.btree.BTreeIndexManagerImpl.LoadPageOperation;
  98. import org.simpledbm.rss.impl.im.btree.BTreeIndexManagerImpl.SearchResult;
  99. import org.simpledbm.rss.impl.latch.LatchFactoryImpl;
  100. import org.simpledbm.rss.impl.locking.LockEventListener;
  101. import org.simpledbm.rss.impl.locking.LockManagerFactoryImpl;
  102. import org.simpledbm.rss.impl.locking.LockManagerImpl;
  103. import org.simpledbm.rss.impl.locking.util.DefaultLockAdaptor;
  104. import org.simpledbm.rss.impl.pm.PageManagerImpl;
  105. import org.simpledbm.rss.impl.sp.SlottedPageImpl;
  106. import org.simpledbm.rss.impl.sp.SlottedPageManagerImpl;
  107. import org.simpledbm.rss.impl.st.FileStorageContainerFactory;
  108. import org.simpledbm.rss.impl.st.StorageManagerImpl;
  109. import org.simpledbm.rss.impl.tx.LoggableFactoryImpl;
  110. import org.simpledbm.rss.impl.tx.TransactionManagerImpl;
  111. import org.simpledbm.rss.impl.tx.TransactionalModuleRegistryImpl;
  112. import org.simpledbm.rss.impl.wal.LogFactoryImpl;
  113. import org.simpledbm.rss.impl.wal.LogManagerImpl;
  114. public class TestBTreeManager extends BaseTestCase {
  115. static final short TYPE_STRINGKEYFACTORY = 25000;
  116. static final short TYPE_ROWLOCATIONFACTORY = 25001;
  117. boolean doCrashTesting = false;
  118. public TestBTreeManager() {
  119. super();
  120. }
  121. public TestBTreeManager(String arg0) {
  122. super(arg0);
  123. }
  124. public TestBTreeManager(String arg0, boolean crashTesting) {
  125. super(arg0);
  126. doCrashTesting = crashTesting;
  127. }
  128. static boolean compressKeys = false;
  129. static boolean largeBM = false;
  130. /**
  131. * A simple string key.
  132. */
  133. public static class StringKey implements IndexKey {
  134. static final String MAX_KEY = "<INFINITY>";
  135. static final String MIN_KEY = "<NEG_INFINITY>";
  136. ByteString string = new ByteString();
  137. public StringKey() {
  138. }
  139. public StringKey(StringKey key) {
  140. string = new ByteString(key.string);
  141. }
  142. public StringKey(ByteBuffer bb) {
  143. string = new ByteString(bb);
  144. }
  145. public IndexKey cloneIndexKey() {
  146. return new StringKey(this);
  147. }
  148. public StringKey(final String s) {
  149. setString(s);
  150. }
  151. public void setBytes(byte[] bytes) {
  152. string = new ByteString(bytes);
  153. }
  154. @Override
  155. public String toString() {
  156. if (isMaxKey()) {
  157. return MAX_KEY;
  158. } else if (isMinKey()) {
  159. return MIN_KEY;
  160. }
  161. return string.toString().trim();
  162. }
  163. public void setString(String string) {
  164. if (MAX_KEY.equals(string)) {
  165. this.string = new ByteString(new byte[1]);
  166. } else if (MIN_KEY.equals(string)) {
  167. byte[] data = { ' ' };
  168. this.string = new ByteString(data);
  169. } else {
  170. byte data[];
  171. if (!compressKeys) {
  172. data = new byte[1024];
  173. Arrays.fill(data, (byte) ' ');
  174. byte[] srcdata = string.getBytes();
  175. System.arraycopy(srcdata, 0, data, 0, srcdata.length);
  176. } else {
  177. data = string.getBytes();
  178. }
  179. this.string = new ByteString(data);
  180. }
  181. }
  182. public int getStoredLength() {
  183. return string.getStoredLength();
  184. }
  185. public void store(ByteBuffer bb) {
  186. string.store(bb);
  187. }
  188. public boolean isMaxKey() {
  189. return string.length() == 1 && string.get(0) == 0;
  190. }
  191. public boolean isMinKey() {
  192. return string.length() == 1 && string.get(0) == ' ';
  193. }
  194. public int compareTo(IndexKey o) {
  195. StringKey sk = (StringKey) o;
  196. if (isMaxKey() || sk.isMaxKey()) {
  197. if (isMaxKey() && sk.isMaxKey()) {
  198. return 0;
  199. } else if (isMaxKey()) {
  200. return 1;
  201. } else {
  202. return -1;
  203. }
  204. } else if (isMinKey() || sk.isMinKey()) {
  205. if (isMinKey() && sk.isMinKey()) {
  206. return 0;
  207. } else if (isMinKey()) {
  208. return -1;
  209. } else {
  210. return 1;
  211. }
  212. }
  213. return string.compareTo(sk.string);
  214. }
  215. @Override
  216. public boolean equals(Object arg0) {
  217. return compareTo((IndexKey) arg0) == 0;
  218. }
  219. }
  220. public static class StringKeyFactory implements IndexKeyFactory {
  221. public IndexKey newIndexKey(int id) {
  222. return new StringKey();
  223. }
  224. public IndexKey maxIndexKey(int id) {
  225. StringKey s = new StringKey();
  226. s.setBytes(new byte[1]);
  227. return s;
  228. }
  229. public IndexKey minIndexKey(int id) {
  230. StringKey s = new StringKey(StringKey.MIN_KEY);
  231. return s;
  232. }
  233. public IndexKey newIndexKey(int containerId, ByteBuffer bb) {
  234. return new StringKey(bb);
  235. }
  236. public IndexKey parseIndexKey(int containerId, String s) {
  237. return new StringKey(s);
  238. }
  239. }
  240. /**
  241. * A simple location.
  242. */
  243. public static class RowLocation extends BaseLockable implements Location {
  244. int loc;
  245. protected RowLocation() {
  246. super((byte) 'R');
  247. }
  248. RowLocation(RowLocation other) {
  249. super(other);
  250. this.loc = other.loc;
  251. }
  252. RowLocation(ByteBuffer bb) {
  253. super((byte) 'R');
  254. loc = bb.getInt();
  255. }
  256. RowLocation(String s) {
  257. super((byte) 'R');
  258. loc = Integer.parseInt(s);
  259. }
  260. public Location cloneLocation() {
  261. return new RowLocation(this);
  262. }
  263. public void store(ByteBuffer bb) {
  264. bb.putInt(loc);
  265. }
  266. public int getStoredLength() {
  267. return Integer.SIZE / Byte.SIZE;
  268. }
  269. public int compareTo(Location o) {
  270. RowLocation rl = (RowLocation) o;
  271. return loc - rl.loc;
  272. }
  273. @Override
  274. public boolean equals(Object o) {
  275. return compareTo((Location) o) == 0;
  276. }
  277. @Override
  278. public int hashCode() {
  279. return loc;
  280. }
  281. @Override
  282. public String toString() {
  283. return Integer.toString(loc);
  284. }
  285. public int getContainerId() {
  286. return loc;
  287. }
  288. public int getX() {
  289. return 0;
  290. }
  291. public int getY() {
  292. return 0;
  293. }
  294. }
  295. public static class RowLocationFactory implements LocationFactory {
  296. public Location newLocation() {
  297. return new RowLocation();
  298. }
  299. public Location newLocation(ByteBuffer bb) {
  300. return new RowLocation(bb);
  301. }
  302. public Location newLocation(String s) {
  303. return new RowLocation(s);
  304. }
  305. }
  306. private IndexItem generateKey(IndexItemFactory btree, String s,
  307. int location, int childpage, boolean isLeaf) {
  308. StringKey key = (StringKey) btree.getNewIndexKey(1, s);
  309. RowLocation loc = (RowLocation) btree.getNewLocation();
  310. loc.loc = location;
  311. IndexItem item = new IndexItem(key, loc, childpage, isLeaf, btree
  312. .isUnique());
  313. return item;
  314. }
  315. /**
  316. * Initialize the test harness. New log is created, and the test container
  317. * initialized. The container is allocated an extent of 64 pages which ought
  318. * to be large enough for all the test cases.
  319. */
  320. void doInitContainer() throws Exception {
  321. final BTreeDB db = new BTreeDB(platform, true);
  322. try {
  323. Transaction trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  324. db.spacemgr.createContainer(trx, "testctr.dat", 1, 1, 20, db.spmgr
  325. .getPageType());
  326. trx.commit();
  327. } finally {
  328. db.shutdown();
  329. }
  330. }
  331. void doInitContainer2() throws Exception {
  332. final BTreeDB db = new BTreeDB(platform, true);
  333. try {
  334. Transaction trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  335. db.btreeMgr.createIndex(trx, "testctr.dat", 1, 20,
  336. TYPE_STRINGKEYFACTORY, TYPE_ROWLOCATIONFACTORY, true);
  337. trx.commit();
  338. } finally {
  339. db.shutdown();
  340. }
  341. }
  342. void doLoadData(ScanResult[] results) throws Exception {
  343. final BTreeDB db = new BTreeDB(platform, false);
  344. try {
  345. IndexContainer index = db.btreeMgr.getIndex(1);
  346. IndexKeyFactory keyFactory = (IndexKeyFactory) db.objectFactory
  347. .getSingleton(TYPE_STRINGKEYFACTORY);
  348. LocationFactory locationFactory = (LocationFactory) db.objectFactory
  349. .getSingleton(TYPE_ROWLOCATIONFACTORY);
  350. for (int i = 0; i < results.length; i++) {
  351. IndexKey key = keyFactory.parseIndexKey(1, results[i].getKey());
  352. Location location = locationFactory.newLocation(results[i]
  353. .getLocation());
  354. Transaction trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  355. index.insert(trx, key, location);
  356. trx.commit();
  357. }
  358. } finally {
  359. db.shutdown();
  360. }
  361. }
  362. void doLoadData(String filename) throws Exception {
  363. BufferedReader reader = new BufferedReader(new InputStreamReader(Thread
  364. .currentThread().getContextClassLoader().getResourceAsStream(
  365. filename)));
  366. final BTreeDB db = new BTreeDB(platform, false);
  367. try {
  368. IndexContainer index = db.btreeMgr.getIndex(1);
  369. IndexKeyFactory keyFactory = (IndexKeyFactory) db.objectFactory
  370. .getSingleton(TYPE_STRINGKEYFACTORY);
  371. LocationFactory locationFactory = (LocationFactory) db.objectFactory
  372. .getSingleton(TYPE_ROWLOCATIONFACTORY);
  373. String line = reader.readLine();
  374. while (line != null) {
  375. StringTokenizer st = new StringTokenizer(line, " ");
  376. String k = st.nextToken();
  377. IndexKey key = keyFactory.parseIndexKey(1, k);
  378. String l = st.nextToken();
  379. Location location = locationFactory.newLocation(l);
  380. Transaction trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  381. // System.out.println("Inserting (" + key + ", " + location +
  382. // ")");
  383. index.insert(trx, key, location);
  384. trx.commit();
  385. line = reader.readLine();
  386. }
  387. } finally {
  388. reader.close();
  389. db.shutdown();
  390. }
  391. }
  392. /**
  393. * Initialize data pages by loading data from specified XML resource.
  394. */
  395. public void doLoadXml(boolean testUnique, String dataFile) throws Exception {
  396. final BTreeDB db = new BTreeDB(platform, false);
  397. try {
  398. BTreeIndexManagerImpl.XMLLoader loader = new BTreeIndexManagerImpl.XMLLoader(
  399. db.btreeMgr);
  400. Transaction trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  401. try {
  402. loader.parseResource(dataFile);
  403. for (LoadPageOperation loadPageOp : loader.getPageOperations()) {
  404. final PageId pageid = loadPageOp.getPageId();
  405. final BTreeIndexManagerImpl btreemgr = db.btreeMgr;
  406. BufferAccessBlock bab = btreemgr.bufmgr.fixExclusive(
  407. pageid, false, -1, 0);
  408. try {
  409. PageId spaceMapPageId = new PageId(pageid
  410. .getContainerId(), loadPageOp
  411. .getSpaceMapPageNumber());
  412. BufferAccessBlock smpBab = btreemgr.bufmgr
  413. .fixExclusive(spaceMapPageId, false, -1, 0);
  414. try {
  415. Lsn lsn = trx.logInsert(bab.getPage(), loadPageOp);
  416. btreemgr.redo(bab.getPage(), loadPageOp);
  417. bab.setDirty(lsn);
  418. btreemgr.redo(smpBab.getPage(), loadPageOp);
  419. smpBab.setDirty(lsn);
  420. } finally {
  421. smpBab.unfix();
  422. }
  423. } finally {
  424. bab.unfix();
  425. }
  426. }
  427. } finally {
  428. // Doesn't matter whether we commit or abort as the changes are
  429. // logged as redo-only.
  430. trx.abort();
  431. }
  432. } finally {
  433. db.shutdown();
  434. }
  435. }
  436. /**
  437. * Initialize data pages by loading data from specified XML resource.
  438. */
  439. public void doValidateTree(String dataFile) throws Exception {
  440. final BTreeDB db = new BTreeDB(platform, false);
  441. try {
  442. doValidateTree(db, dataFile);
  443. } finally {
  444. db.shutdown();
  445. }
  446. }
  447. /**
  448. * Initialize data pages by loading data from specified XML resource.
  449. */
  450. public void doValidateTree(final BTreeDB db, String dataFile)
  451. throws Exception {
  452. BTreeIndexManagerImpl.XMLLoader loader = new BTreeIndexManagerImpl.XMLLoader(
  453. db.btreeMgr);
  454. loader.parseResource(dataFile);
  455. for (LoadPageOperation loadPageOp : loader.getPageOperations()) {
  456. final PageId pageid = loadPageOp.getPageId();
  457. final BTreeIndexManagerImpl btreemgr = db.btreeMgr;
  458. final PlatformObjects po = db.platform
  459. .getPlatformObjects(IndexManager.LOGGER_NAME);
  460. BufferAccessBlock bab = btreemgr.bufmgr.fixExclusive(pageid, false,
  461. -1, 0);
  462. try {
  463. /*
  464. * Log record is being applied to BTree page.
  465. */
  466. SlottedPage r = (SlottedPage) bab.getPage();
  467. BTreeNode node = new BTreeNode(po, loadPageOp
  468. .getIndexItemFactory(), r);
  469. // System.out.println("Validating page ->");
  470. // node.dumpAsXml();
  471. // System.out.println("------------------");
  472. assertEquals(node.header.keyCount, loadPageOp.items.size());
  473. assertEquals(node.header.leftSibling, loadPageOp.leftSibling);
  474. assertEquals(node.header.rightSibling, loadPageOp.rightSibling);
  475. assertEquals(node.header.keyFactoryType, loadPageOp
  476. .getKeyFactoryType());
  477. assertEquals(node.header.locationFactoryType, loadPageOp
  478. .getLocationFactoryType());
  479. assertEquals(node.isLeaf(), loadPageOp.isLeaf());
  480. assertEquals(node.isUnique(), loadPageOp.isUnique());
  481. for (int k = 1, i = 0; k < r.getNumberOfSlots(); k++, i++) {
  482. if (r.isSlotDeleted(k)) {
  483. continue;
  484. }
  485. IndexItem item = loadPageOp.items.get(i);
  486. IndexItem item1 = node.getItem(k);
  487. assertEquals(item, item1);
  488. }
  489. } finally {
  490. bab.unfix();
  491. }
  492. }
  493. }
  494. /*
  495. * Splits page 2 into 2 and 3.
  496. */
  497. void doPageSplit(boolean testLeaf, boolean testUnique) throws Exception {
  498. /* Create the write ahead log */
  499. final BTreeDB db = new BTreeDB(platform, false);
  500. try {
  501. final BTreeImpl btree = db.btreeMgr.getBTreeImpl(1,
  502. TYPE_STRINGKEYFACTORY, TYPE_ROWLOCATIONFACTORY, testUnique);
  503. int pageNumber = 2;
  504. Transaction trx;
  505. BTreeContext bcursor = new BTreeContext(db.tracer);
  506. bcursor.setQ(db.bufmgr.fixForUpdate(new PageId(1, pageNumber), 0));
  507. try {
  508. trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  509. boolean okay = false;
  510. try {
  511. // System.out.println("--> SPLITTING PAGE");
  512. bcursor.searchKey = generateKey(btree.indexItemFactory,
  513. "da", 5, -1, testLeaf);
  514. btree.doSplit(trx, bcursor);
  515. } finally {
  516. if (okay)
  517. trx.commit();
  518. else {
  519. trx.abort();
  520. }
  521. }
  522. } finally {
  523. bcursor.unfixQ();
  524. }
  525. } finally {
  526. db.shutdown();
  527. }
  528. }
  529. /*
  530. * Merges previously split pages 2 and 3.
  531. */
  532. void doRestartAndMerge(boolean testLeaf, boolean testUnique, int l, int r)
  533. throws Exception {
  534. final BTreeDB db = new BTreeDB(platform, false);
  535. final PlatformObjects po = db.platform
  536. .getPlatformObjects(IndexManager.LOGGER_NAME);
  537. try {
  538. final BTreeImpl btree = db.btreeMgr.getBTreeImpl(1,
  539. TYPE_STRINGKEYFACTORY, TYPE_ROWLOCATIONFACTORY, testUnique);
  540. // System.out.println("--> BEFORE MERGE");
  541. BufferAccessBlock bab = db.bufmgr.fixShared(new PageId(1, l), 0);
  542. try {
  543. BTreeNode node = new BTreeNode(po, btree.indexItemFactory, bab
  544. .getPage());
  545. node.dump();
  546. } finally {
  547. bab.unfix();
  548. }
  549. bab = db.bufmgr.fixShared(new PageId(1, r), 0);
  550. try {
  551. BTreeNode node = new BTreeNode(po, btree.indexItemFactory, bab
  552. .getPage());
  553. node.dump();
  554. } finally {
  555. bab.unfix();
  556. }
  557. BTreeContext bcursor = new BTreeContext(db.tracer);
  558. bcursor.setQ(db.bufmgr.fixForUpdate(new PageId(1, l), 0));
  559. bcursor.setR(db.bufmgr.fixForUpdate(new PageId(1, r), 0));
  560. try {
  561. Transaction trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  562. boolean okay = false;
  563. try {
  564. // System.out.println("--> MERGING PAGE");
  565. btree.doMerge(trx, bcursor);
  566. } finally {
  567. if (okay)
  568. trx.commit();
  569. else {
  570. trx.abort();
  571. }
  572. }
  573. } finally {
  574. bcursor.unfixQ();
  575. }
  576. } finally {
  577. db.shutdown();
  578. }
  579. }
  580. /*
  581. * Merges previously split pages 2 and 3.
  582. */
  583. void doRestart() throws Exception {
  584. final BTreeDB db = new BTreeDB(platform, false);
  585. try {
  586. System.out.println("RESTART PROCESSING COMPLETED");
  587. } finally {
  588. db.shutdown();
  589. }
  590. }
  591. void doRestartAndLink(boolean testLeaf, boolean testUnique)
  592. throws Exception {
  593. final BTreeDB db = new BTreeDB(platform, false);
  594. final PlatformObjects po = db.platform
  595. .getPlatformObjects(IndexManager.LOGGER_NAME);
  596. try {
  597. final BTreeImpl btree = db.btreeMgr.getBTreeImpl(1,
  598. TYPE_STRINGKEYFACTORY, TYPE_ROWLOCATIONFACTORY, testUnique);
  599. // System.out.println("--> BEFORE LINKING CHILD TO PARENT");
  600. BufferAccessBlock bab = db.bufmgr.fixShared(new PageId(1, 2), 0);
  601. try {
  602. BTreeNode node = new BTreeNode(po, btree.indexItemFactory, bab
  603. .getPage());
  604. node.dump();
  605. } finally {
  606. bab.unfix();
  607. }
  608. bab = db.bufmgr.fixShared(new PageId(1, 3), 0);
  609. try {
  610. BTreeNode node = new BTreeNode(po, btree.indexItemFactory, bab
  611. .getPage());
  612. node.dump();
  613. } finally {
  614. bab.unfix();
  615. }
  616. // prepareParentPage(pageFactory, bufmgr, btree, 1, 4, testUnique,
  617. // 2);
  618. BTreeContext bcursor = new BTreeContext(db.tracer);
  619. bcursor.setQ(db.bufmgr.fixForUpdate(new PageId(1, 2), 0));
  620. bcursor.setR(db.bufmgr.fixForUpdate(new PageId(1, 3), 0));
  621. bcursor.setP(db.bufmgr.fixForUpdate(new PageId(1, 4), 0));
  622. try {
  623. Transaction trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  624. boolean okay = false;
  625. try {
  626. // System.out.println("--> LINKING CHILD TO PARENT");
  627. btree.doLink(trx, bcursor);
  628. } finally {
  629. if (okay)
  630. trx.commit();
  631. else {
  632. trx.abort();
  633. }
  634. }
  635. } finally {
  636. bcursor.unfixQ();
  637. bcursor.unfixR();
  638. bcursor.unfixP();
  639. }
  640. bcursor.setQ(db.bufmgr.fixForUpdate(new PageId(1, 2), 0));
  641. bcursor.setR(db.bufmgr.fixForUpdate(new PageId(1, 3), 0));
  642. bcursor.setP(db.bufmgr.fixForUpdate(new PageId(1, 4), 0));
  643. try {
  644. Transaction trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  645. boolean okay = false;
  646. try {
  647. // System.out.println("--> DE-LINKING CHILD FROM PARENT");
  648. btree.doUnlink(trx, bcursor);
  649. } finally {
  650. if (okay)
  651. trx.commit();
  652. else {
  653. trx.abort();
  654. }
  655. }
  656. } finally {
  657. bcursor.unfixQ();
  658. bcursor.unfixR();
  659. }
  660. } finally {
  661. db.shutdown();
  662. }
  663. }
  664. void doRestartLink(boolean testLeaf, boolean testUnique) throws Exception {
  665. final BTreeDB db = new BTreeDB(platform, false);
  666. final PlatformObjects po = db.platform
  667. .getPlatformObjects(IndexManager.LOGGER_NAME);
  668. try {
  669. final BTreeImpl btree = db.btreeMgr.getBTreeImpl(1,
  670. TYPE_STRINGKEYFACTORY, TYPE_ROWLOCATIONFACTORY, testUnique);
  671. // System.out.println("--> BEFORE LINKING CHILD TO PARENT");
  672. BufferAccessBlock bab = db.bufmgr.fixShared(new PageId(1, 2), 0);
  673. try {
  674. BTreeNode node = new BTreeNode(po, btree.indexItemFactory, bab
  675. .getPage());
  676. node.dump();
  677. } finally {
  678. bab.unfix();
  679. }
  680. bab = db.bufmgr.fixShared(new PageId(1, 3), 0);
  681. try {
  682. BTreeNode node = new BTreeNode(po, btree.indexItemFactory, bab
  683. .getPage());
  684. node.dump();
  685. } finally {
  686. bab.unfix();
  687. }
  688. // prepareParentPage(pageFactory, bufmgr, btree, 1, 4, testUnique,
  689. // 2);
  690. BTreeContext bcursor = new BTreeContext(db.tracer);
  691. bcursor.setQ(db.bufmgr.fixForUpdate(new PageId(1, 2), 0));
  692. bcursor.setR(db.bufmgr.fixForUpdate(new PageId(1, 3), 0));
  693. bcursor.setP(db.bufmgr.fixForUpdate(new PageId(1, 4), 0));
  694. try {
  695. Transaction trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  696. boolean okay = false;
  697. try {
  698. // System.out.println("--> LINKING CHILD TO PARENT");
  699. btree.doLink(trx, bcursor);
  700. } finally {
  701. if (okay)
  702. trx.commit();
  703. else {
  704. trx.abort();
  705. }
  706. }
  707. } finally {
  708. bcursor.unfixQ();
  709. bcursor.unfixR();
  710. bcursor.unfixP();
  711. }
  712. } finally {
  713. db.shutdown();
  714. }
  715. }
  716. void doRestartDelink(boolean testLeaf, boolean testUnique) throws Exception {
  717. final BTreeDB db = new BTreeDB(platform, false);
  718. try {
  719. final BTreeImpl btree = db.btreeMgr.getBTreeImpl(1,
  720. TYPE_STRINGKEYFACTORY, TYPE_ROWLOCATIONFACTORY, testUnique);
  721. BTreeContext bcursor = new BTreeContext(db.tracer);
  722. bcursor.setQ(db.bufmgr.fixForUpdate(new PageId(1, 2), 0));
  723. bcursor.setR(db.bufmgr.fixForUpdate(new PageId(1, 3), 0));
  724. bcursor.setP(db.bufmgr.fixForUpdate(new PageId(1, 4), 0));
  725. try {
  726. Transaction trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  727. boolean okay = false;
  728. try {
  729. // System.out.println("--> DE-LINKING CHILD FROM PARENT");
  730. btree.doUnlink(trx, bcursor);
  731. } finally {
  732. if (okay)
  733. trx.commit();
  734. else {
  735. trx.abort();
  736. }
  737. }
  738. } finally {
  739. bcursor.unfixQ();
  740. bcursor.unfixR();
  741. }
  742. } finally {
  743. db.shutdown();
  744. }
  745. }
  746. void doRestartAndUnlink(boolean testLeaf, boolean testUnique, int p, int q,
  747. int r) throws Exception {
  748. final BTreeDB db = new BTreeDB(platform, false);
  749. try {
  750. final BTreeImpl btree = db.btreeMgr.getBTreeImpl(1,
  751. TYPE_STRINGKEYFACTORY, TYPE_ROWLOCATIONFACTORY, testUnique);
  752. BTreeContext bcursor = new BTreeContext(db.tracer);
  753. bcursor.setQ(db.bufmgr.fixForUpdate(new PageId(1, q), 0));
  754. bcursor.setR(db.bufmgr.fixForUpdate(new PageId(1, r), 0));
  755. bcursor.setP(db.bufmgr.fixForUpdate(new PageId(1, p), 0));
  756. try {
  757. Transaction trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  758. boolean okay = false;
  759. try {
  760. // System.out.println("--> DE-LINKING CHILD FROM PARENT");
  761. btree.doUnlink(trx, bcursor);
  762. } finally {
  763. if (okay)
  764. trx.commit();
  765. else {
  766. trx.abort();
  767. }
  768. }
  769. } finally {
  770. bcursor.unfixQ();
  771. bcursor.unfixR();
  772. }
  773. } finally {
  774. db.shutdown();
  775. }
  776. }
  777. void doRestartAndRedistribute(boolean testLeaf, boolean testUnique)
  778. throws Exception {
  779. final BTreeDB db = new BTreeDB(platform, false);
  780. final PlatformObjects po = db.platform
  781. .getPlatformObjects(IndexManager.LOGGER_NAME);
  782. try {
  783. final BTreeImpl btree = db.btreeMgr.getBTreeImpl(1,
  784. TYPE_STRINGKEYFACTORY, TYPE_ROWLOCATIONFACTORY, testUnique);
  785. // System.out.println("--> BEFORE REDISTRIBUTING KEYS");
  786. BufferAccessBlock bab = db.bufmgr.fixShared(new PageId(1, 2), 0);
  787. try {
  788. BTreeNode node = new BTreeNode(po, btree.indexItemFactory, bab
  789. .getPage());
  790. node.dump();
  791. } finally {
  792. bab.unfix();
  793. }
  794. bab = db.bufmgr.fixShared(new PageId(1, 3), 0);
  795. try {
  796. BTreeNode node = new BTreeNode(po, btree.indexItemFactory, bab
  797. .getPage());
  798. node.dump();
  799. } finally {
  800. bab.unfix();
  801. }
  802. BTreeContext bcursor = new BTreeContext(db.tracer);
  803. bcursor.setQ(db.bufmgr.fixForUpdate(new PageId(1, 2), 0));
  804. bcursor.setR(db.bufmgr.fixForUpdate(new PageId(1, 3), 0));
  805. try {
  806. Transaction trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  807. boolean okay = false;
  808. try {
  809. bcursor.searchKey = generateKey(btree.indexItemFactory,
  810. "da", 5, -1, testLeaf);
  811. // System.out.println("--> REDISTRIBUTING KEYS");
  812. btree.doRedistribute(trx, bcursor);
  813. } finally {
  814. if (okay)
  815. trx.commit();
  816. else {
  817. trx.abort();
  818. }
  819. }
  820. } finally {
  821. bcursor.unfixQ();
  822. }
  823. } finally {
  824. db.shutdown();
  825. }
  826. }
  827. void doRedistributeIssue28() throws Exception {
  828. boolean testUnique = false;
  829. boolean testLeaf = true;
  830. final BTreeDB db = new BTreeDB(platform, false);
  831. final PlatformObjects po = db.platform
  832. .getPlatformObjects(IndexManager.LOGGER_NAME);
  833. try {
  834. final BTreeImpl btree = db.btreeMgr.getBTreeImpl(1,
  835. TYPE_STRINGKEYFACTORY, TYPE_ROWLOCATIONFACTORY, testUnique);
  836. BufferAccessBlock bab = db.bufmgr.fixShared(new PageId(1, 2), 0);
  837. try {
  838. BTreeNode node = new BTreeNode(po, btree.indexItemFactory, bab
  839. .getPage());
  840. node.dump();
  841. } finally {
  842. bab.unfix();
  843. }
  844. bab = db.bufmgr.fixShared(new PageId(1, 3), 0);
  845. try {
  846. BTreeNode node = new BTreeNode(po, btree.indexItemFactory, bab
  847. .getPage());
  848. node.dump();
  849. } finally {
  850. bab.unfix();
  851. }
  852. BTreeContext bcursor = new BTreeContext(db.tracer);
  853. bcursor.setQ(db.bufmgr.fixForUpdate(new PageId(1, 2), 0));
  854. bcursor.setR(db.bufmgr.fixForUpdate(new PageId(1, 3), 0));
  855. try {
  856. Transaction trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  857. boolean okay = false;
  858. try {
  859. bcursor.searchKey = generateKey(btree.indexItemFactory,
  860. "da", 5, -1, testLeaf);
  861. btree.doRedistribute(trx, bcursor);
  862. } finally {
  863. if (okay)
  864. trx.commit();
  865. else {
  866. trx.abort();
  867. }
  868. }
  869. } finally {
  870. bcursor.unfixQ();
  871. }
  872. } finally {
  873. db.shutdown();
  874. }
  875. }
  876. void doRestartAndIncreaseTreeHeight(boolean testLeaf, boolean testUnique)
  877. throws Exception {
  878. final BTreeDB db = new BTreeDB(platform, false);
  879. final PlatformObjects po = db.platform
  880. .getPlatformObjects(IndexManager.LOGGER_NAME);
  881. try {
  882. final BTreeImpl btree = db.btreeMgr.getBTreeImpl(1,
  883. TYPE_STRINGKEYFACTORY, TYPE_ROWLOCATIONFACTORY, testUnique);
  884. // System.out.println("--> BEFORE INCREASING TREE HEIGHT");
  885. BufferAccessBlock bab = db.bufmgr.fixShared(new PageId(1, 2), 0);
  886. try {
  887. BTreeNode node = new BTreeNode(po, btree.indexItemFactory, bab
  888. .getPage());
  889. node.dump();
  890. } finally {
  891. bab.unfix();
  892. }
  893. bab = db.bufmgr.fixShared(new PageId(1, 3), 0);
  894. try {
  895. BTreeNode node = new BTreeNode(po, btree.indexItemFactory, bab
  896. .getPage());
  897. node.dump();
  898. } finally {
  899. bab.unfix();
  900. }
  901. BTreeContext bcursor = new BTreeContext(db.tracer);
  902. bcursor.setQ(db.bufmgr.fixForUpdate(new PageId(1, 2), 0));
  903. bcursor.setR(db.bufmgr.fixForUpdate(new PageId(1, 3), 0));
  904. try {
  905. Transaction trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  906. boolean okay = false;
  907. try {
  908. bcursor.searchKey = generateKey(btree.indexItemFactory,
  909. "da", 5, -1, testLeaf);
  910. // System.out.println("--> INCREASING TREE HEIGHT");
  911. btree.doIncreaseTreeHeight(trx, bcursor);
  912. } finally {
  913. if (okay)
  914. trx.commit();
  915. else {
  916. trx.abort();
  917. }
  918. }
  919. } finally {
  920. bcursor.unfixQ();
  921. }
  922. } finally {
  923. db.shutdown();
  924. }
  925. }
  926. void doRestartAndDecreaseTreeHeight(boolean testLeaf, boolean testUnique,
  927. int p, int q) throws Exception {
  928. final BTreeDB db = new BTreeDB(platform, false);
  929. final PlatformObjects po = db.platform
  930. .getPlatformObjects(IndexManager.LOGGER_NAME);
  931. try {
  932. final BTreeImpl btree = db.btreeMgr.getBTreeImpl(1,
  933. TYPE_STRINGKEYFACTORY, TYPE_ROWLOCATIONFACTORY, testUnique);
  934. // System.out.println("--> BEFORE DECREASING TREE HEIGHT");
  935. BufferAccessBlock bab = db.bufmgr.fixShared(new PageId(1, p), 0);
  936. try {
  937. BTreeNode node = new BTreeNode(po, btree.indexItemFactory, bab
  938. .getPage());
  939. node.dump();
  940. } finally {
  941. bab.unfix();
  942. }
  943. bab = db.bufmgr.fixShared(new PageId(1, q), 0);
  944. try {
  945. BTreeNode node = new BTreeNode(po, btree.indexItemFactory, bab
  946. .getPage());
  947. node.dump();
  948. } finally {
  949. bab.unfix();
  950. }
  951. BTreeContext bcursor = new BTreeContext(db.tracer);
  952. bcursor.setP(db.bufmgr.fixForUpdate(new PageId(1, p), 0));
  953. bcursor.setQ(db.bufmgr.fixForUpdate(new PageId(1, q), 0));
  954. try {
  955. Transaction trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  956. boolean okay = false;
  957. try {
  958. bcursor.searchKey = generateKey(btree.indexItemFactory,
  959. "da", 5, -1, testLeaf);
  960. // System.out.println("--> DECREASING TREE HEIGHT");
  961. btree.doDecreaseTreeHeight(trx, bcursor);
  962. } finally {
  963. if (okay)
  964. trx.commit();
  965. else {
  966. trx.abort();
  967. }
  968. }
  969. } finally {
  970. bcursor.unfixP();
  971. }
  972. } finally {
  973. db.shutdown();
  974. }
  975. }
  976. void doNewRedistribute(boolean testLeaf) throws Exception {
  977. boolean testUnique = false;
  978. final BTreeDB db = new BTreeDB(platform, false);
  979. final PlatformObjects po = db.platform
  980. .getPlatformObjects(IndexManager.LOGGER_NAME);
  981. try {
  982. final BTreeImpl btree = db.btreeMgr.getBTreeImpl(1,
  983. TYPE_STRINGKEYFACTORY, TYPE_ROWLOCATIONFACTORY, testUnique);
  984. BufferAccessBlock bab = db.bufmgr.fixShared(new PageId(1, 2), 0);
  985. try {
  986. BTreeNode node = new BTreeNode(po, btree.indexItemFactory, bab
  987. .getPage());
  988. node.dump();
  989. } finally {
  990. bab.unfix();
  991. }
  992. bab = db.bufmgr.fixShared(new PageId(1, 3), 0);
  993. try {
  994. BTreeNode node = new BTreeNode(po, btree.indexItemFactory, bab
  995. .getPage());
  996. node.dump();
  997. } finally {
  998. bab.unfix();
  999. }
  1000. BTreeContext bcursor = new BTreeContext(db.tracer);
  1001. bcursor.setQ(db.bufmgr.fixForUpdate(new PageId(1, 2), 0));
  1002. bcursor.setR(db.bufmgr.fixForUpdate(new PageId(1, 3), 0));
  1003. try {
  1004. Transaction trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  1005. boolean okay = false;
  1006. try {
  1007. bcursor.searchKey = generateKey(btree.indexItemFactory,
  1008. "da", 5, -1, testLeaf);
  1009. btree.doNewRedistribute(trx, bcursor);
  1010. } finally {
  1011. if (okay)
  1012. trx.commit();
  1013. else {
  1014. trx.abort();
  1015. }
  1016. }
  1017. } finally {
  1018. bcursor.unfixQ();
  1019. }
  1020. } finally {
  1021. db.shutdown();
  1022. }
  1023. }
  1024. /**
  1025. * Test case for Issue 64.
  1026. */
  1027. void doSearchIssue64() throws Exception {
  1028. final boolean testUnique = false;
  1029. final BTreeDB db = new BTreeDB(platform, false);
  1030. try {
  1031. final BTreeImpl btree = db.btreeMgr.getBTreeImpl(1,
  1032. TYPE_STRINGKEYFACTORY, TYPE_ROWLOCATIONFACTORY, testUnique);
  1033. IndexKeyFactory keyFactory = (IndexKeyFactory) db.objectFactory
  1034. .getSingleton(TYPE_STRINGKEYFACTORY);
  1035. LocationFactory locationFactory = (LocationFactory) db.objectFactory
  1036. .getSingleton(TYPE_ROWLOCATIONFACTORY);
  1037. IndexKey key = keyFactory.parseIndexKey(1, "zzz");
  1038. Location location = locationFactory.newLocation();
  1039. Transaction trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  1040. IndexScan scan = btree.openScan(trx, key, location, true);
  1041. try {
  1042. if (scan.fetchNext()) {
  1043. fail("Unexpected result");
  1044. }
  1045. } catch (SimpleDBMException e) {
  1046. fail("Unexpected exception " + e.getMessage());
  1047. } finally {
  1048. scan.close();
  1049. trx.abort();
  1050. }
  1051. } finally {
  1052. db.shutdown();
  1053. }
  1054. }
  1055. void doSingleInsert(boolean testUnique, boolean commit, String k, String loc)
  1056. throws Exception {
  1057. doSingleInsert(testUnique, commit, k, loc, null, null);
  1058. }
  1059. void doSingleInsert(boolean testUnique, boolean commit, String k,
  1060. String loc, String commitresult, String abortresult)
  1061. throws Exception {
  1062. final BTreeDB db = new BTreeDB(platform, false);
  1063. try {
  1064. final BTreeImpl btree = db.btreeMgr.getBTreeImpl(1,
  1065. TYPE_STRINGKEYFACTORY, TYPE_ROWLOCATIONFACTORY, testUnique);
  1066. IndexKeyFactory keyFactory = (IndexKeyFactory) db.objectFactory
  1067. .getSingleton(TYPE_STRINGKEYFACTORY);
  1068. LocationFactory locationFactory = (LocationFactory) db.objectFactory
  1069. .getSingleton(TYPE_ROWLOCATIONFACTORY);
  1070. IndexKey key = keyFactory.parseIndexKey(1, k);
  1071. Location location = locationFactory.newLocation(loc);
  1072. Transaction trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  1073. boolean okay = false;
  1074. try {
  1075. // System.out.println("--> INSERTING KEY");
  1076. btree.insert(trx, key, location);
  1077. if (commitresult != null) {
  1078. doValidateTree(db, commitresult);
  1079. }
  1080. okay = true;
  1081. } finally {
  1082. if (okay && commit) {
  1083. // System.out.println("--> COMMITTING INSERT");
  1084. trx.commit();
  1085. if (commitresult != null) {
  1086. doValidateTree(db, commitresult);
  1087. }
  1088. } else {
  1089. // System.out.println("--> ABORTING INSERT");
  1090. trx.abort();
  1091. if (abortresult != null) {
  1092. doValidateTree(db, abortresult);
  1093. }
  1094. }
  1095. }
  1096. } finally {
  1097. db.shutdown();
  1098. }
  1099. }
  1100. void doDoubleInsert(boolean testUnique, boolean commit1, String k1,
  1101. String loc1, boolean commit2, String k2, String loc2,
  1102. String result1, String result2, String result3) throws Exception {
  1103. final BTreeDB db = new BTreeDB(platform, false);
  1104. try {
  1105. final BTreeImpl btree = db.btreeMgr.getBTreeImpl(1,
  1106. TYPE_STRINGKEYFACTORY, TYPE_ROWLOCATIONFACTORY, testUnique);
  1107. IndexKeyFactory keyFactory = (IndexKeyFactory) db.objectFactory
  1108. .getSingleton(TYPE_STRINGKEYFACTORY);
  1109. LocationFactory locationFactory = (LocationFactory) db.objectFactory
  1110. .getSingleton(TYPE_ROWLOCATIONFACTORY);
  1111. IndexKey key1 = keyFactory.parseIndexKey(1, k1);
  1112. Location location1 = locationFactory.newLocation(loc1);
  1113. Transaction trx1 = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  1114. boolean okay1 = false;
  1115. try {
  1116. // System.out.println("--> INSERTING KEY 1");
  1117. btree.insert(trx1, key1, location1);
  1118. doValidateTree(db, result1);
  1119. okay1 = true;
  1120. IndexKey key2 = keyFactory.parseIndexKey(1, k2);
  1121. Location location2 = locationFactory.newLocation(loc2);
  1122. Transaction trx2 = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  1123. boolean okay2 = false;
  1124. try {
  1125. // System.out.println("--> INSERTING KEY 2");
  1126. btree.insert(trx2, key2, location2);
  1127. doValidateTree(db, result2);
  1128. okay2 = true;
  1129. } finally {
  1130. if (okay2 && commit2) {
  1131. // System.out.println("--> COMMITTING KEY 2");
  1132. trx2.commit();
  1133. } else {
  1134. // System.out.println("--> ABORTING KEY 2");
  1135. trx2.abort();
  1136. }
  1137. }
  1138. } finally {
  1139. if (okay1 && commit1) {
  1140. // System.out.println("--> COMMITTING KEY 1");
  1141. trx1.commit();
  1142. } else {
  1143. // System.out.println("--> ABORTING KEY 1");
  1144. trx1.abort();
  1145. doValidateTree(db, result3);
  1146. }
  1147. }
  1148. } finally {
  1149. db.shutdown();
  1150. }
  1151. }
  1152. void doSingleDelete(boolean testUnique, boolean commit, String k, String loc)
  1153. throws Exception {
  1154. final BTreeDB db = new BTreeDB(platform, false);
  1155. try {
  1156. final BTreeImpl btree = db.btreeMgr.getBTreeImpl(1,
  1157. TYPE_STRINGKEYFACTORY, TYPE_ROWLOCATIONFACTORY, testUnique);
  1158. IndexKeyFactory keyFactory = (IndexKeyFactory) db.objectFactory
  1159. .getSingleton(TYPE_STRINGKEYFACTORY);
  1160. LocationFactory locationFactory = (LocationFactory) db.objectFactory
  1161. .getSingleton(TYPE_ROWLOCATIONFACTORY);
  1162. IndexKey key = keyFactory.parseIndexKey(1, k);
  1163. Location location = locationFactory.newLocation(loc);
  1164. Transaction trx = db.trxmgr.begin(IsolationMode.SERIALIZABLE);
  1165. boolean okay = false;
  1166. try {
  1167. // System.out.println("--> DELETING KEY");
  1168. btree.delete(trx, key, location);
  1169. okay = true;
  1170. } finally {
  1171. if (okay && commit)
  1172. trx.commit();
  1173. else {
  1174. trx.abort();
  1175. }
  1176. }
  1177. } finally {
  1178. db.shutdown();
  1179. }
  1180. }
  1181. boolean t1Failed = false;
  1182. boolean t2Failed = f

Large files files are truncated, but you can click here to view the full file