Project

General

Profile

h2_synchronization_transactional_fix_20200529a.patch

Constantin Asofiei, 05/30/2020 03:17 PM

Download (8.09 KB)

View differences:

h2/src/main/org/h2/command/Parser.java
1614 1614
            } else if (readIf("IGNORE")) {
1615 1615
                command.setDropAction(ConstraintActionType.SET_DEFAULT);
1616 1616
            }
1617
            if (readIf("TRANSACTIONAL")) {
1618
                command.setTransactional(true);
1619
            }
1617 1620
            return command;
1618 1621
        } else if (readIf("INDEX")) {
1619 1622
            boolean ifExists = readIfExists(false);
......
1626 1629
            if (readIf("ON")) {
1627 1630
                readIdentifierWithSchema();
1628 1631
            }
1632
            if (readIf("TRANSACTIONAL")) {
1633
                command.setTransactional(true);
1634
            }
1629 1635
            return command;
1630 1636
        } else if (readIf("USER")) {
1631 1637
            boolean ifExists = readIfExists(false);
......
4683 4689
                }
4684 4690

  
4685 4691
            }
4692
            if (readIf("TRANSACTIONAL")) {
4693
                command.setTransactional(true);
4694
            }
4686 4695
            command.setHash(hash);
4687 4696
            command.setSpatial(spatial);
4688 4697
            return command;
......
6459 6468
            }
6460 6469
            read("REFERENCES");
6461 6470
            parseReferences(command, schema, tableName);
6471
            if (readIf("TRANSACTIONAL")) {
6472
               command.setTransactional(true);
6473
           }
6462 6474
        } else {
6463 6475
            if (constraintName != null) {
6464 6476
                throw getSyntaxError();
h2/src/main/org/h2/command/ddl/DropIndex.java
41 41

  
42 42
    @Override
43 43
    public int update() {
44
        session.commit(true);
44
        if (!transactional) {
45
            session.commit(true);
46
        }
45 47
        Database db = session.getDatabase();
46 48
        Index index = getSchema().findIndex(session, indexName);
47 49
        if (index == null) {
h2/src/main/org/h2/command/ddl/DropTable.java
125 125

  
126 126
    @Override
127 127
    public int update() {
128
        session.commit(true);
128
        if (!transactional) {
129
            session.commit(true);
130
        }
129 131
        prepareDrop();
130 132
        executeDrop();
131 133
        return 0;
h2/src/main/org/h2/table/RegularTable.java
534 534
    }
535 535

  
536 536
    private boolean doLock2(Session session, int lockMode, boolean exclusive) {
537
        if (exclusive) {
538
            if (lockExclusiveSession == null) {
539
                if (lockSharedSessions.isEmpty()) {
540
                    traceLock(session, exclusive, "added for");
541
                    session.addLock(this);
542
                    lockExclusiveSession = session;
543
                    return true;
544
                } else if (lockSharedSessions.size() == 1 &&
545
                        lockSharedSessions.contains(session)) {
546
                    traceLock(session, exclusive, "add (upgraded) for ");
547
                    lockExclusiveSession = session;
548
                    return true;
549
                }
550
            }
551
        } else {
552
            if (lockExclusiveSession == null) {
553
                if (lockMode == Constants.LOCK_MODE_READ_COMMITTED) {
554
                    if (!database.isMultiThreaded() && !database.isMultiVersion()) {
555
                        // READ_COMMITTED: a read lock is acquired,
556
                        // but released immediately after the operation
557
                        // is complete.
558
                        // When allowing only one thread, no lock is
559
                        // required.
560
                        // Row level locks work like read committed.
537
        synchronized (this) {
538
            if (exclusive) {
539
                if (lockExclusiveSession == null) {
540
                    if (lockSharedSessions.isEmpty()) {
541
                        traceLock(session, exclusive, "added for");
542
                        session.addLock(this);
543
                        lockExclusiveSession = session;
544
                        return true;
545
                    } else if (lockSharedSessions.size() == 1 &&
546
                            lockSharedSessions.contains(session)) {
547
                        traceLock(session, exclusive, "add (upgraded) for ");
548
                        lockExclusiveSession = session;
561 549
                        return true;
562 550
                    }
563 551
                }
564
                if (!lockSharedSessions.contains(session)) {
565
                    traceLock(session, exclusive, "ok");
566
                    session.addLock(this);
567
                    lockSharedSessions.add(session);
552
            } else {
553
                if (lockExclusiveSession == null) {
554
                    if (lockMode == Constants.LOCK_MODE_READ_COMMITTED) {
555
                        if (!database.isMultiThreaded() && !database.isMultiVersion()) {
556
                            // READ_COMMITTED: a read lock is acquired,
557
                            // but released immediately after the operation
558
                            // is complete.
559
                            // When allowing only one thread, no lock is
560
                            // required.
561
                            // Row level locks work like read committed.
562
                            return true;
563
                        }
564
                    }
565
                    if (!lockSharedSessions.contains(session)) {
566
                        traceLock(session, exclusive, "ok");
567
                        session.addLock(this);
568
                        lockSharedSessions.add(session);
569
                    }
570
                    return true;
568 571
                }
569
                return true;
570 572
            }
571 573
        }
572 574
        return false;
......
639 641
                    }
640 642
                }
641 643
            }
642
            if (error == null && lockExclusiveSession != null) {
643
                Table t = lockExclusiveSession.getWaitForLock();
644
                if (t != null) {
645
                    error = t.checkDeadlock(lockExclusiveSession, clash, visited);
646
                    if (error != null) {
647
                        error.add(session);
644
            synchronized (this)
645
            {
646
                if (error == null && lockExclusiveSession != null) {
647
                    Table t = lockExclusiveSession.getWaitForLock();
648
                    if (t != null) {
649
                        error = t.checkDeadlock(lockExclusiveSession, clash, visited);
650
                        if (error != null) {
651
                            error.add(session);
652
                        }
648 653
                    }
649 654
                }
650 655
            }
......
667 672
    @Override
668 673
    public void unlock(Session s) {
669 674
        if (database != null) {
670
            traceLock(s, lockExclusiveSession == s, "unlock");
671
            if (lockExclusiveSession == s) {
672
                lockExclusiveSession = null;
673
            }
674
            synchronized (database) {
675
            synchronized (this) {
676
                traceLock(s, lockExclusiveSession == s, "unlock");
677
                if (lockExclusiveSession == s) {
678
                    lockExclusiveSession = null;
679
                }
675 680
                if (!lockSharedSessions.isEmpty()) {
676 681
                    lockSharedSessions.remove(s);
677 682
                }
683
            }
684
            synchronized (database) {
678 685
                if (!waitingSessions.isEmpty()) {
679 686
                    database.notifyAll();
680 687
                }
......
720 727
        scanIndex.remove(session);
721 728
        database.removeMeta(session, getId());
722 729
        scanIndex = null;
723
        lockExclusiveSession = null;
730
        synchronized (this)
731
        {
732
            lockExclusiveSession = null;
733
        }
724 734
        lockSharedSessions = null;
725 735
        invalidate();
726 736
    }