1 21 22 package org.apache.derby.impl.store.raw.xact; 23 24 import org.apache.derby.iapi.reference.SQLState; 25 26 import org.apache.derby.iapi.store.raw.ContainerKey; 27 28 import org.apache.derby.iapi.services.context.ContextManager; 29 import org.apache.derby.iapi.services.daemon.Serviceable; 30 import org.apache.derby.iapi.services.locks.LockFactory; 31 import org.apache.derby.iapi.services.locks.Limit; 32 33 import org.apache.derby.iapi.store.raw.ContainerHandle; 34 import org.apache.derby.iapi.store.raw.Compensation; 35 import org.apache.derby.iapi.store.raw.GlobalTransactionId; 36 import org.apache.derby.iapi.store.raw.LockingPolicy; 37 import org.apache.derby.iapi.store.raw.Loggable; 38 import org.apache.derby.iapi.store.raw.RecordHandle; 39 import org.apache.derby.iapi.store.raw.StreamContainerHandle; 40 import org.apache.derby.iapi.store.raw.Transaction; 41 42 import org.apache.derby.iapi.store.raw.data.DataFactory; 43 import org.apache.derby.iapi.store.raw.data.RawContainerHandle; 44 45 import org.apache.derby.iapi.store.raw.xact.RawTransaction; 46 import org.apache.derby.iapi.store.raw.xact.TransactionId; 47 48 import org.apache.derby.iapi.store.raw.log.LogFactory; 49 import org.apache.derby.iapi.store.raw.log.LogInstant; 50 import org.apache.derby.iapi.store.raw.log.Logger; 51 52 import org.apache.derby.iapi.store.access.FileResource; 53 import org.apache.derby.iapi.store.access.RowSource; 54 import org.apache.derby.iapi.store.access.TransactionController; 55 import org.apache.derby.iapi.error.ExceptionSeverity; 56 57 import org.apache.derby.iapi.services.property.PersistentSet; 58 59 import org.apache.derby.catalog.UUID; 60 61 import java.util.Stack ; 62 import java.util.Enumeration ; 63 import java.util.Properties ; 64 import java.util.ArrayList ; 65 import java.util.List ; 66 import java.util.Dictionary ; 67 68 import org.apache.derby.iapi.error.StandardException; 69 70 import org.apache.derby.iapi.services.sanity.SanityManager; 71 import org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream; 72 import org.apache.derby.iapi.util.ByteArray; 73 import org.apache.derby.iapi.services.property.PropertyUtil; 74 import org.apache.derby.iapi.reference.Property; 75 76 import org.apache.derby.impl.store.raw.log.LogToFile; 77 78 import org.apache.derby.iapi.services.io.LimitObjectInput; 79 80 import org.apache.derby.iapi.services.context.ContextService; 81 82 98 public class Xact extends RawTransaction implements Limit { 99 100 103 104 protected static final int CLOSED = 0; 105 protected static final int IDLE = 1; 106 protected static final int ACTIVE = 2; 107 protected static final int UPDATE = 3; 108 protected static final int PREPARED = 4; 109 110 111 114 115 public static final int END_ABORTED = 0x00000001; 116 public static final int END_PREPARED = 0x00000002; 117 public static final int END_COMMITTED = 0x00000004; 118 119 public static final int RECOVERY_ROLLBACK_FIRST = 0x00000010; 120 public static final int INTERNAL_TRANSACTION = 0x00000020; 121 public static final int NESTED_TOP_TRANSACTION = 0x00000040; 122 123 124 129 private static final int COMMIT_SYNC = 0x00010000; 130 private static final int COMMIT_NO_SYNC = 0x00020000; 131 private static final int COMMIT_PREPARE = 0x00040000; 132 133 134 137 138 private int savedEndStatus; 142 143 private boolean needSync; 148 149 private boolean justCreated = true; 163 164 165 protected XactContext xc; 167 protected final XactFactory xactFactory; 169 protected final DataFactory dataFactory; 170 protected final LogFactory logFactory; 171 protected final Object compatibilitySpace; 172 173 private LockingPolicy defaultLocking; 175 176 private GlobalTransactionId myGlobalId; 178 179 private volatile TransactionId myId; 181 182 protected Logger logger; 184 185 protected volatile int state; private Integer inComplete = null; 188 private boolean seenUpdates; 200 private boolean inPostCommitProcessing; 211 private LogInstant logStart; 216 private LogInstant logLast; 219 private Stack savePoints; 221 protected List postCommitWorks; protected List postTerminationWorks; private boolean recoveryTransaction; 228 DynamicByteArrayOutputStream logBuffer; 229 230 private boolean postCompleteMode; 232 private boolean sanityCheck_xaclosed; 238 239 private String transName; 242 243 private boolean readOnly; 245 246 private boolean backupBlocked; 250 251 252 255 256 protected Xact( 257 XactFactory xactFactory, 258 LogFactory logFactory, 259 DataFactory dataFactory, 260 boolean readOnly, 261 Object compatibilitySpace) 262 { 263 264 super(); 265 266 this.xactFactory = xactFactory; 267 this.logFactory = logFactory; 268 this.dataFactory = dataFactory; 269 this.readOnly = readOnly; 270 271 this.compatibilitySpace = 272 (compatibilitySpace == null ? this : compatibilitySpace); 273 274 if (SanityManager.DEBUG) 275 { 276 SanityManager.ASSERT(dataFactory != null, "datafactory is null"); 277 SanityManager.ASSERT(xactFactory != null, "xactfactory is null"); 278 SanityManager.ASSERT(logFactory != null, "logfactory is null"); 279 } 280 281 282 resetDefaultLocking(); 283 284 xactFactory.setNewTransactionId((XactId)null, this); 286 287 setIdleState(); 288 289 backupBlocked = false; 290 291 295 } 296 297 298 301 302 304 public final LockFactory getLockFactory() { 305 return xactFactory.getLockFactory(); 306 } 307 308 public final DataFactory getDataFactory() { 309 return dataFactory; 310 } 311 312 315 public long[] getCacheStats(String cacheName) { 316 return getDataFactory().getCacheStats(cacheName); 317 } 318 319 322 public void resetCacheStats(String cacheName) { 323 getDataFactory().resetCacheStats(cacheName); 324 } 325 326 331 public boolean anyoneBlocked() { 332 return getLockFactory().anyoneBlocked(); 333 } 334 335 public DynamicByteArrayOutputStream getLogBuffer() { 336 337 if (logBuffer == null) { 338 logBuffer = new DynamicByteArrayOutputStream(1024); 339 } else { 340 logBuffer.reset(); 341 } 342 343 return logBuffer; 344 } 345 346 354 public void logAndUndo(Compensation compensation, LogInstant undoInstant, LimitObjectInput in) 355 throws StandardException 356 { 357 if (SanityManager.DEBUG) { 358 SanityManager.ASSERT(logStart != null); 359 } 360 361 setActiveState(); 362 363 if (state == ACTIVE) 364 setUpdateState(); 365 366 seenUpdates = true; 367 368 LogInstant clrInstant = logger.logAndUndo(this, compensation, undoInstant, in); 369 370 setLastLogInstant(clrInstant); 371 372 if ((savePoints != null) && !savePoints.empty()) { 374 375 SavePoint sp = (SavePoint) savePoints.peek(); 376 if (sp.getSavePoint() == null) 377 sp.setSavePoint(clrInstant); 378 } 379 } 380 381 384 public void addUpdateTransaction(int transactionStatus) 385 { 386 if (myId != null) 393 xactFactory.addUpdateTransaction(myId, this, transactionStatus); 394 395 } 396 397 398 public void removeUpdateTransaction() 399 { 400 if (myId != null) 401 xactFactory.removeUpdateTransaction(myId); 402 403 } 406 407 408 public void prepareTransaction() 409 { 410 412 if (myId != null) 413 { 414 417 xactFactory.prepareTransaction(myId); 418 } 419 } 420 421 424 public void setFirstLogInstant(LogInstant instant) 425 { 426 if (SanityManager.DEBUG) { 427 SanityManager.ASSERT(instant != null); 428 SanityManager.ASSERT(logStart == null); 429 } 430 431 logStart = instant; 432 } 433 434 437 public LogInstant getFirstLogInstant() 438 { 439 return logStart; 440 } 441 442 445 public void setLastLogInstant(LogInstant instant) 446 { 447 if (SanityManager.DEBUG) { 448 SanityManager.ASSERT(instant != null); 449 } 450 451 logLast = instant; 452 } 453 454 457 public LogInstant getLastLogInstant() 458 { 459 return logLast; 460 } 461 462 465 public void setTransactionId(GlobalTransactionId extid, TransactionId localid) { 466 467 if (SanityManager.DEBUG) { 468 469 if (!(state == IDLE || state == Xact.ACTIVE || 471 (state== CLOSED && justCreated))) 472 { 473 SanityManager.THROWASSERT( 474 "my state is not idle nor active " + state); 475 } 476 } 477 478 myGlobalId = extid; 479 myId = localid; 480 481 if (SanityManager.DEBUG) 482 { 483 if (SanityManager.DEBUG_ON("XATrace") && extid != null) 484 { 485 SanityManager.DEBUG( 486 "XATrace","setting xid: " + myId + " " + myGlobalId 487 + " state " + state + " " + this); 488 489 SanityManager.showTrace(new Throwable ()); 490 } 492 } 493 494 } 495 496 public void setTransactionId(Loggable beginXact, TransactionId localId) 497 { 498 if (SanityManager.DEBUG) { 499 SanityManager.ASSERT((state == IDLE) || (state == ACTIVE)); 501 SanityManager.ASSERT(beginXact instanceof BeginXact); 502 } 503 504 myId = localId; 505 myGlobalId = ((BeginXact)beginXact).getGlobalId(); 506 } 507 508 511 512 516 public void setup(PersistentSet set) 517 throws StandardException { 518 519 int escalationThreshold = PropertyUtil.getServiceInt(set, 520 Property.LOCKS_ESCALATION_THRESHOLD, 521 Property.MIN_LOCKS_ESCALATION_THRESHOLD, 522 Integer.MAX_VALUE, 523 Property.DEFAULT_LOCKS_ESCALATION_THRESHOLD); 524 525 526 getLockFactory().setLimit(this, this, escalationThreshold, this); 527 528 } 529 530 534 public final GlobalTransactionId getGlobalId() 535 { 536 537 return myGlobalId; 538 } 539 540 public final ContextManager getContextManager() 541 { 542 return(xc.getContextManager()); 543 } 544 545 556 public Object getCompatibilitySpace() 557 { 558 if (SanityManager.DEBUG) 559 { 560 SanityManager.ASSERT( 561 compatibilitySpace != null, 562 "cannot have a null compatibilitySpace."); 563 } 564 565 return(this.compatibilitySpace); 566 } 567 568 569 573 public final TransactionId getId() { 574 575 if (SanityManager.DEBUG) 576 SanityManager.ASSERT( 577 myId != null, "cannot have a transaction with null id"); 578 579 return myId; 580 } 581 582 586 protected final TransactionId getIdNoCheck() 587 { 588 return myId; 589 } 590 591 594 public final String getContextId() 595 { 596 return (xc == null) ? null : xc.getIdName(); 597 } 598 599 600 616 617 public LockingPolicy getDefaultLockingPolicy() 618 { 619 return(defaultLocking); 620 } 621 622 623 624 public final LockingPolicy newLockingPolicy(int mode, int isolation, boolean stricterOk) { 625 626 return xactFactory.getLockingPolicy(mode, isolation, stricterOk); 627 628 } 629 630 631 public final void setDefaultLockingPolicy(LockingPolicy policy) { 632 633 if (policy == null) 634 policy = xactFactory.getLockingPolicy(LockingPolicy.MODE_NONE, TransactionController.ISOLATION_NOLOCK, false); 635 defaultLocking = policy; 636 } 637 638 641 public LogInstant commit() throws StandardException 642 { 643 return commit(COMMIT_SYNC); 644 } 645 646 649 public LogInstant commitNoSync(int commitflag) throws StandardException 650 { 651 if (SanityManager.DEBUG) 652 { 653 int checkflag = Transaction.RELEASE_LOCKS|Transaction.KEEP_LOCKS; 654 655 SanityManager.ASSERT((commitflag & checkflag) != 0, 656 "commitNoSync must specify whether to keep or release locks"); 657 658 SanityManager.ASSERT((commitflag & checkflag) != checkflag, 659 "cannot set both RELEASE and KEEP LOCKS flag"); 660 661 if ((commitflag & 662 TransactionController.READONLY_TRANSACTION_INITIALIZATION) 663 != 0) 664 { 665 SanityManager.ASSERT((state == IDLE) || (state == ACTIVE)); 666 } 667 } 668 669 if (state == IDLE && savePoints == null && 678 ((commitflag & TransactionController.READONLY_TRANSACTION_INITIALIZATION) != 0)) 679 return null; 680 681 return commit(COMMIT_NO_SYNC | commitflag); 682 } 683 684 688 689 702 private LogInstant prepareCommit(int commitflag) 703 throws StandardException 704 { 705 LogInstant flushTo = null; 706 707 if (state == CLOSED) 708 { 709 throw StandardException.newException( 710 SQLState.XACT_PROTOCOL_VIOLATION); 711 } 712 713 if (SanityManager.DEBUG) 714 { 715 if ((commitflag & Transaction.KEEP_LOCKS) != 0) 716 { 717 SanityManager.ASSERT( 720 (((commitflag & COMMIT_NO_SYNC) != 0) || 721 ((commitflag & COMMIT_PREPARE) != 0)), 722 "can keep locks around only in commitNoSync or prepare"); 723 724 SanityManager.ASSERT( 725 isUserTransaction(), 726 "KEEP_LOCKS can only be set on user transaction commits"); 727 } 728 } 729 730 731 try { 732 733 preComplete(COMMIT); 734 735 737 if (seenUpdates) { 738 739 EndXact ex = 740 new EndXact( 741 getGlobalId(), 742 ((commitflag & COMMIT_PREPARE) == 0 ? 743 END_COMMITTED : END_PREPARED) 744 | statusForEndXactLog()); 745 746 flushTo = logger.logAndDo(this, ex); 747 748 if (xactFactory.flushLogOnCommit(xc.getIdName())) 749 { 750 if ((commitflag & COMMIT_SYNC) == 0) 751 { 752 needSync = true; 755 } 756 else 757 { 758 logger.flush(flushTo); 759 needSync = false; 760 } 761 } 762 } 763 else if (needSync && (commitflag & COMMIT_SYNC) != 0) 764 { 765 logger.flushAll(); 769 needSync = false; 770 } 771 } 772 catch (StandardException se) 773 { 774 775 779 if (se.getSeverity() < ExceptionSeverity.TRANSACTION_SEVERITY) 780 { 781 throw StandardException.newException( 782 SQLState.XACT_COMMIT_EXCEPTION, se); 783 } 784 785 throw se; 786 787 } 788 return flushTo; 789 } 790 791 802 private void completeCommit(int commitflag) 803 throws StandardException 804 { 805 postComplete(commitflag, COMMIT); 807 808 if ((commitflag & Transaction.KEEP_LOCKS) == 0) 810 { 811 postTermination(); 813 } 814 else 815 { 816 820 if (SanityManager.DEBUG) 821 SanityManager.ASSERT(myGlobalId == null, 822 "calling commit with KEEP_LOCKS on a global transaction"); 823 824 setActiveState(); 827 } 828 829 myGlobalId = null; 830 return; 831 } 832 833 837 private LogInstant commit(int commitflag) 838 throws StandardException 839 { 840 if (SanityManager.DEBUG) 841 { 842 if (SanityManager.DEBUG_ON("XATrace")) 843 SanityManager.DEBUG("XATrace","commiting "); 844 } 845 846 LogInstant flushTo = prepareCommit(commitflag); 847 848 completeCommit(commitflag); 849 850 return(flushTo); 851 } 852 853 854 858 public void abort() throws StandardException { 859 860 if (SanityManager.DEBUG) 861 { 862 if (SanityManager.DEBUG_ON("XATrace")) 863 SanityManager.DEBUG("XATrace","aborting "); 864 } 865 866 if (state == CLOSED) 867 { 868 875 if (SanityManager.DEBUG) 876 { 877 if (!sanityCheck_xaclosed) 880 { 881 throw StandardException.newException( 882 SQLState.XACT_PROTOCOL_VIOLATION); 883 } 884 } 885 886 return; 892 } 893 894 902 903 try { 904 preComplete(ABORT); 905 906 if (getFirstLogInstant() != null) { 908 if (logger == null) 909 { 910 throw StandardException.newException(SQLState.XACT_CANNOT_ABORT_NULL_LOGGER); 911 } 912 913 logger.undo( 914 this, getId(), getFirstLogInstant(), getLastLogInstant()); 915 916 EndXact ex = new EndXact(getGlobalId(), 917 END_ABORTED | statusForEndXactLog()); 918 919 logger.flush(logger.logAndDo(this, ex)); 920 } 921 else if (needSync) 922 { 923 logger.flushAll(); 927 } 928 929 needSync = false; 930 931 } catch (StandardException se) { 932 933 946 if (se.getSeverity() < ExceptionSeverity.SYSTEM_SEVERITY) 947 { 948 throw logFactory.markCorrupt( 949 StandardException.newException( 950 SQLState.XACT_ABORT_EXCEPTION, se)); 951 } 952 953 throw se; 954 955 } 956 957 postComplete(0, ABORT); 959 960 if (postCommitWorks != null && !postCommitWorks.isEmpty()) 963 { 964 postCommitWorks.clear(); 965 } 966 967 postTermination(); 971 972 myGlobalId = null; 973 } 974 975 988 public void reprepare() 989 throws StandardException 990 { 991 if (state == CLOSED) 992 { 993 throw StandardException.newException( 994 SQLState.XACT_PROTOCOL_VIOLATION); 995 } 996 997 if (SanityManager.DEBUG) 1000 { 1001 SanityManager.ASSERT(myGlobalId != null); 1002 SanityManager.ASSERT(state == PREPARED); 1003 } 1004 1005 try 1006 { 1007 if (logger == null) 1008 { 1009 throw StandardException.newException( 1010 SQLState.XACT_CANNOT_ABORT_NULL_LOGGER); 1011 } 1012 1013 1018 state = UPDATE; 1019 1020 logger.reprepare( 1022 this, getId(), getFirstLogInstant(), getLastLogInstant()); 1023 1024 state = PREPARED; 1026 1027 seenUpdates = true; 1028 1029 } catch (StandardException se) { 1030 1031 1044 if (se.getSeverity() < ExceptionSeverity.SYSTEM_SEVERITY) 1045 { 1046 throw logFactory.markCorrupt( 1047 StandardException.newException( 1048 SQLState.XACT_ABORT_EXCEPTION, se)); 1049 } 1050 1051 throw se; 1052 } 1053 1054 } 1057 1058 1066 public void destroy() throws StandardException 1067 { 1068 if (state != CLOSED) 1069 abort(); 1070 1071 close(); 1072 } 1073 1074 1082 public void close() throws StandardException { 1083 1084 1085 1093 1094 switch (state) { 1095 case CLOSED: 1096 return; 1097 case IDLE: 1098 break; 1099 default: 1100 throw StandardException.newException( 1101 SQLState.XACT_TRANSACTION_NOT_IDLE); 1102 } 1103 1104 if (SanityManager.DEBUG) { 1105 1106 SanityManager.ASSERT(xc.getTransaction() == this); 1107 1108 SanityManager.ASSERT( 1109 (postCommitWorks == null || postCommitWorks.isEmpty()), 1110 "cannot close a transaction with post commit work pending"); 1111 1112 if (myGlobalId != null) 1114 sanityCheck_xaclosed = true; 1115 } 1116 1117 getLockFactory().clearLimit(this, this); 1118 1119 if (SanityManager.DEBUG) 1120 { 1121 if (SanityManager.DEBUG_ON("XATrace")) 1122 SanityManager.DEBUG("XATrace","closing " + myId + " " + myGlobalId); 1123 } 1125 1126 if (myId != null) 1128 xactFactory.remove((XactId)myId); 1129 1130 xc.popMe(); 1131 xc = null; 1132 1133 myGlobalId = null; 1134 myId = null; 1135 logStart = null; 1136 logLast = null; 1137 1138 1139 1140 1143 state = CLOSED; 1144 1145 } 1146 1147 1159 public void logAndDo(Loggable operation) throws StandardException { 1160 1161 LogInstant instant = null; 1162 1163 if (logger == null) 1164 getLogger(); 1165 1166 if (logger == null) 1167 { 1168 throw StandardException.newException( 1169 SQLState.XACT_CANNOT_LOG_CHANGE); 1170 } 1171 1172 setActiveState(); 1173 1174 if (state == ACTIVE) 1175 { 1176 instant = 1177 logger.logAndDo( 1178 this, 1179 new BeginXact(getGlobalId(), statusForBeginXactLog())); 1180 1181 setUpdateState(); 1182 } 1183 seenUpdates = true; 1184 1185 if (operation != null) 1186 { 1187 instant = logger.logAndDo(this, operation); 1188 if (instant != null) { 1189 setLastLogInstant(instant); 1190 1191 if ((savePoints != null) && !savePoints.empty()) { 1192 for (int i = savePoints.size() - 1; i >= 0; i--) { 1193 1196 SavePoint sp = (SavePoint) savePoints.elementAt(i); 1197 if (sp.getSavePoint() == null) { 1198 sp.setSavePoint(instant); 1199 } else 1200 break; 1201 } 1202 } 1203 } 1204 1205 } 1206 else 1207 { 1208 if (instant != null) 1209 setLastLogInstant(instant); 1210 } 1211 1212 } 1213 1214 public void addPostCommitWork(Serviceable work) 1215 { 1216 if (recoveryTransaction) 1217 return; 1218 1219 if (postCommitWorks == null) 1220 postCommitWorks = new ArrayList (1); 1221 postCommitWorks.add(work); 1222 } 1223 1224 public void addPostTerminationWork(Serviceable work) 1225 { 1226 if (recoveryTransaction) 1227 return; 1228 1229 if (postTerminationWorks == null) 1230 postTerminationWorks = new ArrayList (2); 1231 postTerminationWorks.add(work); 1232 } 1233 1234 1235 1248 1255 1259 public ContainerHandle openContainer(ContainerKey containerId, int mode) 1260 throws StandardException { 1261 1262 return openContainer(containerId, defaultLockingPolicy(), mode); 1263 } 1264 1265 1269 public ContainerHandle openContainer(ContainerKey containerId, LockingPolicy locking, int mode) 1270 throws StandardException { 1271 1272 setActiveState(); 1273 1274 if (locking == null) 1275 locking = xactFactory.getLockingPolicy(LockingPolicy.MODE_NONE, TransactionController.ISOLATION_NOLOCK, false); 1276 1277 return dataFactory.openContainer(this, containerId, locking, mode); 1278 } 1279 1280 1286 public RawContainerHandle openDroppedContainer(ContainerKey containerId, LockingPolicy locking) 1287 throws StandardException 1288 { 1289 setActiveState(); 1290 1291 if (locking == null) 1292 locking = xactFactory.getLockingPolicy(LockingPolicy.MODE_NONE, TransactionController.ISOLATION_NOLOCK, false); 1293 1294 RawContainerHandle hdl = null; 1295 1296 try 1298 { 1299 hdl = dataFactory.openDroppedContainer(this, containerId, locking, 1300 ContainerHandle.MODE_FORUPDATE); 1301 } 1302 catch (StandardException se) 1303 { 1304 hdl = dataFactory.openDroppedContainer(this, containerId, 1306 locking, 1307 ContainerHandle.MODE_READONLY); 1308 } 1309 1310 return hdl; 1311 } 1312 1313 1314 1318 public long addContainer(long segmentId, long containerid, int mode, Properties tableProperties, int temporaryFlag) 1319 throws StandardException { 1320 1321 setActiveState(); 1322 1323 return dataFactory.addContainer(this, segmentId, containerid, mode, tableProperties, temporaryFlag); 1324 } 1325 1326 1330 public long addAndLoadStreamContainer(long segmentId, Properties tableProperties, RowSource rowSource) 1331 throws StandardException { 1332 1333 setActiveState(); 1334 1335 return dataFactory.addAndLoadStreamContainer(this, segmentId, tableProperties, rowSource); 1336 1337 } 1338 1339 1343 public StreamContainerHandle openStreamContainer( 1344 long segmentId, 1345 long containerId, 1346 boolean hold) 1347 throws StandardException 1348 { 1349 setActiveState(); 1350 1351 return( 1352 dataFactory.openStreamContainer( 1353 this, segmentId, containerId, hold)); 1354 } 1355 1356 1360 public void dropStreamContainer(long segmentId, long containerId) 1361 throws StandardException { 1362 1363 setActiveState(); 1364 1365 dataFactory.dropStreamContainer(this, segmentId, containerId); 1366 } 1367 1368 1378 public void reCreateContainerForRedoRecovery 1379 (long segmentId, long containerId, ByteArray containerInfo) 1380 throws StandardException 1381 { 1382 setActiveState(); 1383 1384 dataFactory.reCreateContainerForRedoRecovery( 1385 this, segmentId, containerId, containerInfo); 1386 } 1387 1388 1392 public void dropContainer(ContainerKey containerId) 1393 throws StandardException { 1394 1395 setActiveState(); 1396 1397 dataFactory.dropContainer(this, containerId); 1398 } 1399 1400 1404 public int setSavePoint(String name, Object kindOfSavepoint) 1405 throws StandardException 1406 { 1407 1408 if (kindOfSavepoint != null && kindOfSavepoint instanceof String ) 1409 { 1410 1412 throwExceptionIfSQLSavepointNotAllowed(kindOfSavepoint); 1415 } 1416 1417 if (getSavePointPosition(name, kindOfSavepoint, false) != -1) 1420 { 1421 throw StandardException.newException( 1422 SQLState.XACT_SAVEPOINT_EXISTS); 1423 } 1424 1425 if (savePoints == null) 1426 savePoints = new Stack (); 1427 1428 savePoints.push(new SavePoint(name, kindOfSavepoint)); 1429 1430 if (SanityManager.DEBUG) { 1431 1432 if (SanityManager.DEBUG_ON("memoryLeakTrace")) { 1433 1434 if (savePoints.size() > 20) 1435 System.out.println("memoryLeakTrace:Xact:savepoints " + savePoints.size()); 1436 } 1437 } 1438 return savePoints.size(); 1439 } 1440 1441 1445 1449 private void throwExceptionIfSQLSavepointNotAllowed(Object kindOfSavepoint) 1450 throws StandardException 1451 { 1452 1453 boolean foundUserSavepoint = false; 1454 1455 if ((savePoints != null) && !savePoints.empty()) { 1456 for (int i = savePoints.size() - 1; i >= 0; i--) { 1457 SavePoint sp = (SavePoint) savePoints.elementAt(i); 1458 if (sp.isThisUserDefinedsavepoint()) 1459 { 1460 1462 foundUserSavepoint = true; 1463 break; 1464 } 1465 } 1466 } 1467 1468 if (foundUserSavepoint) 1469 throw StandardException.newException( 1470 SQLState.XACT_MAX_SAVEPOINT_LEVEL_REACHED); 1471 } 1472 1473 1477 public int releaseSavePoint(String name, Object kindOfSavepoint) 1478 throws StandardException 1479 { 1480 int position = getSavePointPosition(name, kindOfSavepoint, true); 1481 1482 if (position == -1) 1483 { 1484 1488 if (kindOfSavepoint != null && !(kindOfSavepoint instanceof String )) 1489 { 1490 1494 name = name.substring(2); 1495 } 1496 throw StandardException.newException( 1497 SQLState.XACT_SAVEPOINT_NOT_FOUND, name); 1498 } 1499 1500 popSavePoints(position, true); 1501 return savePoints.size(); 1502 } 1503 1504 1508 public int rollbackToSavePoint(String name, Object kindOfSavepoint) 1509 throws StandardException 1510 { 1511 int position = getSavePointPosition(name, kindOfSavepoint, true); 1512 1513 if (position == -1) 1514 { 1515 if (kindOfSavepoint != null && !(kindOfSavepoint instanceof String )) 1519 name = name.substring(2); 1520 throw StandardException.newException( 1521 SQLState.XACT_SAVEPOINT_NOT_FOUND, name); 1522 } 1523 1524 notifyObservers(SAVEPOINT_ROLLBACK); 1525 1526 popSavePoints(position, false); 1527 return savePoints.size(); 1528 } 1529 1530 1531 1534 1535 1538 private void getLogger() { 1539 1540 logger = logFactory.getLogger(); 1541 } 1542 1543 1544 1548 protected void assumeIdentity(TransactionTableEntry ent) 1549 { 1550 if (ent != null) 1551 { 1552 if (SanityManager.DEBUG) 1553 { 1554 SanityManager.ASSERT(ent.getXid() != null, "TTE.xid is null"); 1555 1556 SanityManager.ASSERT( 1557 ent.getFirstLog() != null, "TTE.firstLog is null"); 1558 } 1559 1560 ent.setXact(this); 1562 1563 myId = ent.getXid(); 1564 logStart = ent.getFirstLog(); 1565 logLast = ent.getLastLog(); 1566 1567 1568 myGlobalId = null; 1580 1581 if (state == IDLE) 1583 state = ACTIVE; 1584 1585 if (SanityManager.DEBUG) 1586 { 1587 if (state != ACTIVE && state != UPDATE && state != PREPARED) 1588 SanityManager.THROWASSERT( 1589 "recovery transaction have illegal state " + state + 1590 "xact = " + this); 1591 } 1592 1593 1594 1595 if (logger == null) 1596 getLogger(); 1597 1598 savedEndStatus = 0; 1599 } 1600 else 1601 { 1602 myGlobalId = null; 1603 myId = null; 1604 logStart = null; 1605 logLast = null; 1606 state = IDLE; 1607 } 1608 } 1609 1610 1620 protected void assumeGlobalXactIdentity( 1621 TransactionTableEntry ent) 1622 { 1623 if (SanityManager.DEBUG) 1624 { 1625 SanityManager.ASSERT(ent != null); 1626 SanityManager.ASSERT(ent.getXid() != null, "TTE.xid is null"); 1627 SanityManager.ASSERT( 1628 ent.getFirstLog() != null, "TTE.firstLog is null"); 1629 SanityManager.ASSERT(ent.isPrepared()); 1630 } 1631 1632 myId = ent.getXid(); 1633 myGlobalId = ent.getGid(); 1634 logStart = ent.getFirstLog(); 1635 logLast = ent.getLastLog(); 1636 1637 if (state == IDLE) 1639 { 1640 if (SanityManager.DEBUG) 1641 { 1642 if (SanityManager.DEBUG_ON("XATrace")) 1643 SanityManager.DEBUG("XATrace","set active state in assume Global XactIdentity"); 1644 } 1645 1646 state = ACTIVE; 1647 } 1648 1649 if (ent.isPrepared()) 1650 state = PREPARED; 1651 1652 ent.setXact(this); 1654 1655 if (SanityManager.DEBUG) 1656 { 1657 if (state != ACTIVE && state != UPDATE && state != PREPARED) 1658 SanityManager.THROWASSERT( 1659 "recovery transaction have illegal state " + state + 1660 "xact = " + this); 1661 } 1662 1663 if (logger == null) 1664 getLogger(); 1665 1666 savedEndStatus = 0; 1667 1668 if (SanityManager.DEBUG) 1669 { 1670 SanityManager.ASSERT(myGlobalId != null); 1671 1672 SanityManager.ASSERT(state == PREPARED); 1674 } 1675 } 1676 1677 1678 1682 private final void setUpdateState() throws StandardException { 1683 1684 1690 1691 if (SanityManager.DEBUG) 1692 { 1693 SanityManager.ASSERT( 1694 state == ACTIVE, 1695 "setting update state without first going thru ACTIVE state"); 1696 1697 SanityManager.ASSERT( 1698 myId != null, 1699 "setting update state to a trasnaction with Null ID"); 1700 } 1701 1702 if (SanityManager.DEBUG) 1703 { 1704 if (SanityManager.DEBUG_ON("XATrace")) 1705 { 1706 SanityManager.DEBUG("XATrace","set update state"); 1707 SanityManager.showTrace(new Throwable ()); 1708 } 1709 } 1710 1711 if (readOnly) 1712 { 1713 throw StandardException.newException( 1714 SQLState.XACT_PROTOCOL_VIOLATION); 1715 } 1716 1717 state = UPDATE; 1718 } 1719 1720 protected void setIdleState() { 1721 1722 if (SanityManager.DEBUG) 1723 SanityManager.ASSERT(myId != null, "setIdleState got null ID"); 1724 1725 if (SanityManager.DEBUG) 1726 { 1727 if (SanityManager.DEBUG_ON("TranTrace")) 1728 { 1729 SanityManager.DEBUG( 1730 "TranTrace", "transaction going idle " + myId); 1731 1732 SanityManager.showTrace(new Throwable ("TranTrace")); 1733 } 1734 } 1735 1736 1737 1741 { 1744 state = IDLE; 1745 } 1746 1747 1748 1749 seenUpdates = false; 1750 1751 1757 logStart = null; 1758 logLast = null; 1759 1760 if (SanityManager.DEBUG) 1761 { 1762 if (SanityManager.DEBUG_ON("XATrace")) 1763 SanityManager.DEBUG("XATrace","set idle state : " + state + " " + this); 1764 } 1765 1766 } 1767 1768 protected final void setActiveState() throws StandardException { 1769 1770 if ((state == CLOSED) || (!inAbort() && (state == PREPARED))) 1771 { 1772 throw StandardException.newException( 1774 SQLState.XACT_PROTOCOL_VIOLATION); 1775 } 1776 1777 if (SanityManager.DEBUG) 1778 SanityManager.ASSERT(myId != null, "setActiveState got null ID"); 1779 1780 if (state == IDLE) 1781 { 1782 synchronized(this) 1783 { 1784 state = ACTIVE; 1785 } 1786 1787 if (SanityManager.DEBUG) 1788 { 1789 if (SanityManager.DEBUG_ON("XATrace")) 1790 { 1791 SanityManager.DEBUG("XATrace","set active state " + this); 1792 SanityManager.showTrace(new Throwable ("XATrace")); 1793 } 1794 } 1795 1796 1797 if (!justCreated) 1798 xactFactory.setNewTransactionId(myId, this); 1799 1800 justCreated = false; 1801 1802 if (SanityManager.DEBUG) 1803 { 1804 if (SanityManager.DEBUG_ON("TranTrace")) 1805 { 1806 SanityManager.DEBUG( 1807 "TranTrace", "transaction going active " + myId); 1808 1809 SanityManager.showTrace(new Throwable ("TranTrace")); 1810 } 1811 } 1812 1813 } 1814 } 1815 1816 1827 protected final void setPrepareState() 1828 throws StandardException 1829 { 1830 if (state == PREPARED || state == CLOSED) 1831 { 1832 throw StandardException.newException( 1833 SQLState.XACT_PROTOCOL_VIOLATION); 1834 } 1835 1836 if (SanityManager.DEBUG) 1837 { 1838 SanityManager.ASSERT( 1839 state == UPDATE, 1840 "setting PREPARED state without first going thru UPDATE state"); 1841 SanityManager.ASSERT( 1842 myId != null, 1843 "setting PREPARED state to a transaction with Null ID"); 1844 } 1845 1846 state = PREPARED; 1847 } 1848 1849 1850 public final LockingPolicy defaultLockingPolicy() { 1851 return defaultLocking; 1852 } 1853 1854 1855 private final void releaseAllLocks() { 1856 1857 getLockFactory().unlockGroup(getCompatibilitySpace(), this); 1858 } 1859 1860 void resetDefaultLocking() { 1861 1862 setDefaultLockingPolicy( 1863 newLockingPolicy(LockingPolicy.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, true)); 1864 1865 if (SanityManager.DEBUG) { 1866 SanityManager.ASSERT(defaultLocking != null); 1867 } 1868 1869 } 1870 1871 protected void preComplete(Integer commitOrAbort) throws StandardException { 1872 1873 1879 if (inComplete != null) 1880 if (commitOrAbort.equals(COMMIT)) 1881 throw logFactory.markCorrupt( 1882 StandardException.newException(SQLState.XACT_COMMIT_EXCEPTION)); 1883 else 1884 throw logFactory.markCorrupt( 1885 StandardException.newException(SQLState.XACT_ABORT_EXCEPTION)); 1886 1887 inComplete = commitOrAbort; 1888 if (!postCompleteMode) 1889 doComplete(commitOrAbort); 1890 1891 } 1892 1893 protected void postComplete(int commitflag, Integer commitOrAbort) throws StandardException { 1894 1895 if (postCompleteMode) 1896 doComplete(commitOrAbort); 1897 1898 if ((commitflag & Transaction.KEEP_LOCKS) == 0) 1901 { 1902 releaseAllLocks(); 1903 } 1904 else 1905 { 1906 if (SanityManager.DEBUG) 1907 { 1908 SanityManager.ASSERT(commitOrAbort.equals(COMMIT), 1909 "cannot keep locks around after an ABORT"); 1910 } 1911 } 1912 1913 setIdleState(); 1914 1915 inComplete = null; 1916 } 1917 1918 protected void doComplete(Integer commitOrAbort) throws StandardException { 1919 1920 if (savePoints != null) 1922 savePoints.removeAllElements(); 1923 1924 notifyObservers(commitOrAbort); 1926 1927 checkObserverException(); 1928 1929 if (SanityManager.DEBUG) 1930 { 1931 if (countObservers() != 0) 1932 { 1933 System.out.println( 1934 "There should be 0 observers, but we still have " 1935 + countObservers() + " observers."); 1936 notifyObservers(null); 1937 } 1938 } 1939 } 1940 1941 private void checkObserverException() throws StandardException { 1942 if (observerException != null) { 1943 StandardException se = observerException; 1944 observerException = null; 1945 throw se; 1946 } 1947 } 1948 1949 1956 protected boolean doPostCommitWorkInTran() 1957 { 1958 return (!inPostCommitProcessing && 1959 !recoveryTransaction && 1960 isUserTransaction() && 1961 (myGlobalId == null)); 1962 } 1963 1964 public boolean handlesPostTerminationWork() 1965 { 1966 return (recoveryTransaction == false); 1968 } 1969 1970 public void recoveryTransaction() 1971 { 1972 recoveryTransaction = true; 1973 1974 xactFactory.remove(myId); 1980 1981 } 1982 1983 1984 private final void postTermination() throws StandardException 1985 { 1986 int count = (postTerminationWorks == null) ? 1988 0 : postTerminationWorks.size(); 1989 1990 for (int i = 0; i < count; i++) 1991 addPostCommitWork((Serviceable)postTerminationWorks.get(i)); 1992 1993 if (count > 0) 1994 postTerminationWorks.clear(); 1995 1996 1997 if (postCommitWorks != null && !postCommitWorks.isEmpty()) 2001 { 2002 int pcsize = postCommitWorks.size(); 2003 2004 if (doPostCommitWorkInTran()) 2006 { 2007 try 2008 { 2009 inPostCommitProcessing = true; 2010 2011 Serviceable[] work = new Serviceable[pcsize]; 2014 work = (Serviceable[])postCommitWorks.toArray(work); 2015 2016 postCommitWorks.clear(); 2020 2021 boolean doWorkInThisThread = xactFactory.inDatabaseCreation(); 2024 2025 for (int i = 0; i < pcsize; i++) 2026 { 2027 2028 if (doWorkInThisThread || work[i].serviceImmediately()) 2033 { 2034 try 2035 { 2036 if (work[i].performWork(xc.getContextManager()) == Serviceable.DONE) 2040 work[i] = null; 2041 2042 } 2045 catch (StandardException se) 2046 { 2047 work[i] = null; 2049 2050 xc.cleanupOnError(se); 2052 } 2053 } 2054 2055 if (work[i] != null) 2062 { 2063 boolean needHelp = xactFactory.submitPostCommitWork(work[i]); 2064 work[i] = null; 2065 if (needHelp) 2066 doWorkInThisThread = true; 2067 } 2068 } 2069 } 2070 finally 2071 { 2072 inPostCommitProcessing = false; 2073 2074 if (postCommitWorks != null) 2076 postCommitWorks.clear(); 2077 } 2078 2079 } 2080 else 2081 { 2082 for (int i = 0; i < pcsize; i++) 2086 { 2087 xactFactory.submitPostCommitWork((Serviceable)postCommitWorks.get((i))); 2089 } 2090 } 2091 2092 postCommitWorks.clear(); 2093 2094 } 2095 2096 unblockBackup(); 2100 } 2101 2102 2106 private int getSavePointPosition( 2107 String name, 2108 Object kindOfSavepoint, 2109 boolean forRollbackOrRelease) 2110 { 2111 if ((savePoints == null) || (savePoints.empty())) 2112 return -1; 2113 2114 for (int i = savePoints.size() - 1; i >= 0; i--) 2115 { 2116 SavePoint savepoint = (SavePoint)savePoints.elementAt(i); 2117 2118 if (savepoint.getName().equals(name)) 2119 { 2120 if (forRollbackOrRelease && 2121 savepoint.getKindOfSavepoint() != null) 2122 { 2123 if (savepoint.getKindOfSavepoint().equals(kindOfSavepoint)) 2124 return(i); 2125 } 2126 else 2127 { 2128 return(i); 2129 } 2130 } 2131 } 2132 return -1; 2133 } 2134 2135 2146 protected boolean popSavePoints(int position, boolean release) throws StandardException { 2147 2148 if (release) { 2149 savePoints.setSize(position); 2150 return false; 2151 } 2152 2153 LogInstant rollbackTo = null; 2154 2155 int size = savePoints.size(); 2156 for (int i = position; i < size; i++) { 2157 SavePoint rollbackSavePoint = (SavePoint) savePoints.elementAt(i); 2158 2159 LogInstant li = rollbackSavePoint.getSavePoint(); 2160 if (li != null) { 2161 rollbackTo = li; 2162 break; 2163 } 2164 } 2165 2166 savePoints.setSize(position + 1); 2167 2168 if (rollbackTo == null) 2169 return false; 2170 2171 try { 2173 2174 logger.undo(this, getId(), rollbackTo, getLastLogInstant()); 2175 2176 } catch (StandardException se) { 2177 2178 2182 if (se.getSeverity() < ExceptionSeverity.TRANSACTION_SEVERITY) 2183 { 2184 throw StandardException.newException( 2185 SQLState.XACT_ROLLBACK_EXCEPTION, se); 2186 } 2187 2188 throw se; 2189 } 2190 2191 return true; 2192 } 2193 2194 2197 public RawTransaction startNestedTopTransaction() throws StandardException { 2198 2199 return xactFactory.startNestedTopTransaction(xc.getFactory(), xc.getContextManager()); 2200 } 2201 2202 2207 private boolean isUserTransaction() 2208 { 2209 String context_id = getContextId(); 2210 2211 return( 2212 (context_id == XactFactory.USER_CONTEXT_ID || 2213 context_id.equals(XactFactory.USER_CONTEXT_ID))); 2214 } 2215 2216 2229 public final boolean isActive() 2230 { 2231 int localState = state; 2234 2235 2236 return (localState != CLOSED && localState != IDLE); 2237 } 2238 2239 2247 public final boolean isPrepared() 2248 { 2249 return(state == PREPARED); 2252 } 2253 2254 2261 public boolean isIdle() 2262 { 2263 if (SanityManager.DEBUG) 2266 { 2267 if (SanityManager.DEBUG_ON("XATrace")) 2268 SanityManager.DEBUG("XATrace","RawTran, isIdle, state = " + state); 2269 } 2270 2271 return (state == IDLE); 2272 } 2273 2274 2281 public boolean isPristine() 2282 { 2283 return (state == IDLE || state == ACTIVE); 2284 } 2285 2286 public boolean inAbort() { 2287 return ABORT.equals(inComplete); 2288 } 2289 2290 public FileResource getFileHandler() { 2291 return dataFactory.getFileHandler(); 2292 } 2293 2294 2295 2299 protected int statusForBeginXactLog() 2300 { 2301 return recoveryRollbackFirst() ? RECOVERY_ROLLBACK_FIRST : 0; 2302 } 2303 2304 2308 protected int statusForEndXactLog() 2309 { 2310 return savedEndStatus; 2314 } 2315 2316 2321 void setPostComplete() { 2322 postCompleteMode = true; 2323 } 2324 2325 2326 2336 public boolean blockBackup(boolean wait) 2337 throws StandardException 2338 { 2339 if (!backupBlocked) { 2340 backupBlocked = xactFactory.blockBackup(wait); 2341 } 2342 2343 return backupBlocked; 2344 } 2345 2346 2351 private void unblockBackup() { 2352 if (backupBlocked) 2353 xactFactory.unblockBackup(); 2354 backupBlocked = false; 2355 } 2356 2357 2358 2363 public boolean isBlockingBackup() { 2364 return backupBlocked; 2365 } 2366 2367 2370 2371 2374 2375 public void reached(Object compatabilitySpace, Object group, int limit, 2376 Enumeration lockList, int lockCount) 2377 throws StandardException { 2378 2379 Dictionary containers = new java.util.Hashtable (); 2381 2382 for (; lockList.hasMoreElements(); ) { 2383 2384 Object plainLock = lockList.nextElement(); 2385 if (!(plainLock instanceof RecordHandle)) { 2386 continue; 2388 } 2389 2390 ContainerKey ckey = ((RecordHandle) plainLock).getContainerId(); 2391 2392 LockCount lc = (LockCount) containers.get(ckey); 2393 if (lc == null) { 2394 lc = new LockCount(); 2395 containers.put(ckey, lc); 2396 } 2397 lc.count++; 2398 } 2399 2400 int threshold = limit / (containers.size() + 1); 2403 if (threshold < (limit / 4)) 2404 threshold = limit / 4; 2405 2406 2409 boolean didEscalate = false; 2410 for (Enumeration e = containers.keys(); e.hasMoreElements(); ) { 2411 ContainerKey ckey = (ContainerKey) e.nextElement(); 2412 2413 LockCount lc = (LockCount) containers.get(ckey); 2414 2415 if (lc.count < threshold) { 2416 continue; 2417 } 2418 2419 try 2420 { 2421 if (openContainer(ckey, 2422 new RowLocking3Escalate(getLockFactory()), 2423 ContainerHandle.MODE_OPEN_FOR_LOCK_ONLY | 2424 ContainerHandle.MODE_FORUPDATE | 2425 ContainerHandle.MODE_LOCK_NOWAIT) != null) 2426 { 2427 2428 didEscalate = true; 2429 } 2430 } 2431 catch (StandardException se) 2432 { 2433 if (!se.getMessageId().equals(SQLState.LOCK_TIMEOUT)) 2434 { 2435 throw se; 2438 } 2439 } 2440 } 2441 2442 if (didEscalate) { 2458 notifyObservers(LOCK_ESCALATE); 2459 checkObserverException(); 2460 } 2461 } 2462 2463 2480 public void createXATransactionFromLocalTransaction( 2481 int format_id, 2482 byte[] global_id, 2483 byte[] branch_id) 2484 throws StandardException 2485 { 2486 GlobalXactId gid = new GlobalXactId(format_id, global_id, branch_id); 2487 2488 if (((TransactionTable) xactFactory.getTransactionTable()). 2489 findTransactionContextByGlobalId(gid) != null) 2490 { 2491 throw StandardException.newException(SQLState.STORE_XA_XAER_DUPID); 2492 } 2493 2494 setTransactionId(gid, this.getId()); 2495 2496 if (SanityManager.DEBUG) 2497 SanityManager.ASSERT(myGlobalId != null); 2498 } 2499 2500 2512 public void xa_commit( 2513 boolean onePhase) 2514 throws StandardException 2515 { 2516 if (SanityManager.DEBUG) 2517 SanityManager.ASSERT(state != CLOSED); 2518 2519 if (onePhase) 2520 { 2521 if (state == PREPARED) 2522 { 2523 throw StandardException.newException( 2524 SQLState.XACT_PROTOCOL_VIOLATION); 2525 } 2526 2527 prepareCommit(COMMIT_SYNC); 2528 2529 completeCommit(COMMIT_SYNC); 2530 } 2531 else 2532 { 2533 if (state != PREPARED) 2534 { 2535 throw StandardException.newException( 2536 SQLState.XACT_PROTOCOL_VIOLATION); 2537 } 2538 2539 prepareCommit(COMMIT_SYNC); 2540 2541 completeCommit(COMMIT_SYNC); 2542 } 2543 2544 2545 return; 2546 } 2547 2548 2562 public int xa_prepare() 2563 throws StandardException 2564 { 2565 if (SanityManager.DEBUG) 2566 { 2567 if (state == CLOSED) 2568 { 2569 SanityManager.THROWASSERT( 2570 "state = " + state + ";myGlobalId = " + myGlobalId); 2571 } 2572 2573 if (SanityManager.DEBUG_ON("XATrace")) 2574 SanityManager.DEBUG("XATrace","in xa_prepare, state is " + state); 2575 } 2576 2577 if ((state == IDLE) || (state == ACTIVE)) 2578 { 2579 abort(); 2580 return(Transaction.XA_RDONLY); 2581 } 2582 else 2583 { 2584 prepareCommit( 2585 COMMIT_SYNC | COMMIT_PREPARE | Transaction.KEEP_LOCKS); 2586 inComplete = null; 2589 2590 setPrepareState(); 2591 2592 return(Transaction.XA_OK); 2593 } 2594 } 2595 2596 2605 public void xa_rollback() 2606 throws StandardException 2607 { 2608 if (SanityManager.DEBUG) 2609 SanityManager.ASSERT(state != CLOSED); 2610 2611 abort(); 2612 2613 return; 2614 } 2615 2616 2628 public String toString() 2629 { 2630 try 2632 { 2633 return(myId.toString()); 2634 } 2635 catch (Throwable t) 2636 { 2637 return("null"); 2641 } 2642 } 2643 2644 2645 2661 public String getActiveStateTxIdString() 2662 { 2663 if(!justCreated && state == IDLE) 2664 { 2665 xactFactory.setNewTransactionId(myId, this); 2667 justCreated = true; 2670 } 2671 2672 return toString(); 2673 } 2674 2675 2676 2677 String getState() 2678 { 2679 int localState ; 2680 2681 { 2684 localState = state; 2685 } 2686 2687 switch (localState) 2688 { 2689 case CLOSED: 2690 return "CLOSED"; 2691 case IDLE: 2692 return "IDLE"; 2693 case ACTIVE: 2694 case UPDATE: 2695 return "ACTIVE"; 2696 2697 case PREPARED: 2698 return "PREPARED"; 2699 } 2700 return null; 2701 } 2702 2703 public String getTransName() 2704 { 2705 return transName; 2706 } 2707 2708 public void setTransName(String name) 2709 { 2710 transName = name; 2711 } 2712 2713 2714 2715 2718 public boolean inRollForwardRecovery() 2719 { 2720 return logFactory.inRFR(); 2721 } 2722 2723 2724 2727 public void checkpointInRollForwardRecovery(LogInstant cinstant, 2728 long redoLWM) 2729 throws StandardException 2730 { 2731 logFactory.checkpointInRFR(cinstant, redoLWM, dataFactory); 2732 } 2733 2734} 2735 2736class LockCount { 2737 int count; 2738} 2739 2740 2741 | Popular Tags |