|
24 | 24 | import com.evolvedbinary.j8fu.fsm.AtomicFSM;
|
25 | 25 | import com.evolvedbinary.j8fu.fsm.FSM;
|
26 | 26 | import com.evolvedbinary.j8fu.lazy.AtomicLazyVal;
|
27 |
| -import net.jcip.annotations.GuardedBy; |
28 | 27 | import net.jcip.annotations.ThreadSafe;
|
29 | 28 | import org.apache.logging.log4j.LogManager;
|
30 | 29 | import org.apache.logging.log4j.Logger;
|
|
87 | 86 | import java.util.Map.Entry;
|
88 | 87 | import java.util.concurrent.ConcurrentHashMap;
|
89 | 88 | import java.util.concurrent.ConcurrentSkipListSet;
|
| 89 | +import java.util.concurrent.atomic.AtomicBoolean; |
90 | 90 | import java.util.concurrent.locks.Lock;
|
91 | 91 | import java.util.concurrent.locks.ReentrantLock;
|
92 | 92 | import java.util.function.Consumer;
|
@@ -249,7 +249,7 @@ public String getStatus() {
|
249 | 249 | /**
|
250 | 250 | * Indicates whether the database is operating in read-only mode
|
251 | 251 | */
|
252 |
| - @GuardedBy("itself") private Boolean readOnly = Boolean.FALSE; |
| 252 | + private final AtomicBoolean readOnly = new AtomicBoolean(); |
253 | 253 |
|
254 | 254 | @ConfigurationFieldAsAttribute("pageSize")
|
255 | 255 | private final int pageSize;
|
@@ -451,10 +451,9 @@ void initialize() throws EXistException, DatabaseConfigurationException {
|
451 | 451 | _initialize();
|
452 | 452 | } catch(final Throwable e) {
|
453 | 453 | // remove that file lock we may have acquired in canReadDataDir
|
454 |
| - synchronized(readOnly) { |
455 |
| - if (dataLock != null && !readOnly) { |
456 |
| - dataLock.release(); |
457 |
| - } |
| 454 | + |
| 455 | + if (dataLock != null && !readOnly.get()) { |
| 456 | + dataLock.release(); |
458 | 457 | }
|
459 | 458 |
|
460 | 459 | if(e instanceof EXistException) {
|
@@ -975,29 +974,25 @@ public NotificationService getNotificationService() {
|
975 | 974 | * @return <code>true</code> if transactions can be handled
|
976 | 975 | */
|
977 | 976 | public boolean isRecoveryEnabled() {
|
978 |
| - synchronized(readOnly) { |
979 |
| - return !readOnly && recoveryEnabled; |
980 |
| - } |
| 977 | + return !readOnly.get() && recoveryEnabled; |
981 | 978 | }
|
982 | 979 |
|
983 | 980 | @Override
|
984 | 981 | public boolean isReadOnly() {
|
985 |
| - synchronized(readOnly) { |
986 |
| - if(!readOnly) { |
987 |
| - final long freeSpace = FileUtils.measureFileStore(dataLock.getFile(), FileStore::getUsableSpace); |
988 |
| - if (freeSpace != -1 && freeSpace < diskSpaceMin) { |
989 |
| - LOG.fatal("Partition containing DATA_DIR: {} is running out of disk space [minimum: {} free: {}]. Switching eXist-db into read-only mode to prevent data loss!", dataLock.getFile().toAbsolutePath().toString(), diskSpaceMin, freeSpace); |
990 |
| - setReadOnly(); |
991 |
| - } |
| 982 | + final boolean isReadOnly = readOnly.get(); |
| 983 | + if (!isReadOnly) { |
| 984 | + final long freeSpace = FileUtils.measureFileStore(dataLock.getFile(), FileStore::getUsableSpace); |
| 985 | + if (freeSpace != -1 && freeSpace < diskSpaceMin) { |
| 986 | + LOG.fatal("Partition containing DATA_DIR: {} is running out of disk space [minimum: {} free: {}]. Switching eXist-db into read-only mode to prevent data loss!", dataLock.getFile().toAbsolutePath().toString(), diskSpaceMin, freeSpace); |
| 987 | + setReadOnly(); |
992 | 988 | }
|
993 |
| - return readOnly; |
994 | 989 | }
|
| 990 | + return readOnly.get(); |
995 | 991 | }
|
996 | 992 |
|
997 | 993 | public void setReadOnly() {
|
998 |
| - LOG.warn("Switching database into read-only mode!"); |
999 |
| - synchronized (readOnly) { |
1000 |
| - readOnly = true; |
| 994 | + if (readOnly.compareAndSet(false, true)) { |
| 995 | + LOG.warn("Switched database into read-only mode!"); |
1001 | 996 | }
|
1002 | 997 | }
|
1003 | 998 |
|
@@ -1728,12 +1723,9 @@ void shutdown(final boolean killed, final Consumer<String> shutdownInstanceConsu
|
1728 | 1723 |
|
1729 | 1724 | //Clear the living instances container
|
1730 | 1725 | shutdownInstanceConsumer.accept(instanceName);
|
1731 |
| - |
1732 |
| - synchronized (readOnly) { |
1733 |
| - if (!readOnly) { |
1734 |
| - // release the lock on the data directory |
1735 |
| - dataLock.release(); |
1736 |
| - } |
| 1726 | + if (!readOnly.get()) { |
| 1727 | + // release the lock on the data directory |
| 1728 | + dataLock.release(); |
1737 | 1729 | }
|
1738 | 1730 |
|
1739 | 1731 | //clearing additional resources, like ThreadLocal
|
|
0 commit comments