Skip to content

Commit

Permalink
pool:make readonly pool READONLY
Browse files Browse the repository at this point in the history
Motivation

When there is a hardware issue for a disk and it is not possibale to write files to that disk anymore.
Nonthenless in dCache world we still write files, and we test the state of the disk by creating a file and etc.

This is a first patch that should help to fix this issue.

Modification

Add enum describing 3 states  ok, READ_ONLY and Failed

Result

no results yet and this should be tested

Acked-by: Tigran
Target: master
Require-book: no
Require-notes: yes
  • Loading branch information
mksahakyan committed Dec 13, 2023
1 parent 523738e commit 862963e
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import static org.dcache.namespace.FileAttribute.STORAGEINFO;
import static org.dcache.util.Exceptions.messageOrClassName;

import com.google.common.collect.Sets;
import diskCacheV111.util.AccessLatency;
import diskCacheV111.util.CacheException;
import diskCacheV111.util.DiskErrorCacheException;
Expand Down Expand Up @@ -306,7 +305,7 @@ public void remove(PnfsId id) throws CacheException {
* Calls through to the wrapped meta data store.
*/
@Override
public boolean isOk() {
public FileStoreState isOk() {
return _replicaStore.isOk();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public long getTotalSpace() {
}

@Override
public boolean isOk() {
return false;
public FileStoreState isOk() {
return FileStoreState.FAILED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ public interface FileStore {
* Returns whether the store appears healthy. How this is determined is up to the
* implementation.
*/
boolean isOk();
FileStoreState isOk();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.dcache.pool.repository;

public enum FileStoreState {
OK, READ_ONLY, FAILED
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ public long getTotalSpace() throws IOException {
}

@Override
public boolean isOk() {
public FileStoreState isOk() {
try {
Path tmp = _dataDir.resolve(".repository_is_ok");
Files.deleteIfExists(tmp);
Files.createFile(tmp);
return true;
return FileStoreState.OK;
} catch (IOException e) {
return false;
return FileStoreState.FAILED;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void remove(PnfsId id) throws CacheException {
}

@Override
public boolean isOk() {
public FileStoreState isOk() {
return delegate().isOk();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void remove(PnfsId id)
* Returns whether the store appears healthy. How this is determined is up to the
* implementation.
*/
boolean isOk();
FileStoreState isOk();

/**
* Closes the store and frees any associated resources.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ public Set<PnfsId> index(IndexOption... options) {
}

@Override
public boolean isOk() {
public FileStoreState isOk() {
return _inner.isOk();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.dcache.pool.repository.FileStoreState;
import org.dcache.pool.repository.ReplicaStore;
import org.dcache.pool.repository.RepositoryChannel;
import org.dcache.util.configuration.ConfigurationMapFactoryBean;
Expand Down Expand Up @@ -147,20 +148,20 @@ public void close() {
}

@Override
public synchronized boolean isOk() {
public synchronized FileStoreState isOk() {
Path tmp = dir.resolve(".repository_is_ok");
try {
Files.deleteIfExists(tmp);
Files.createFile(tmp);

if (database.isFailed()) {
return false;
return FileStoreState.FAILED;
}

return true;
return FileStoreState.OK;
} catch (IOException e) {
LOGGER.error("Failed to touch {}: {}", tmp, messageOrClassName(e));
return false;
return FileStoreState.FAILED;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.dcache.pool.repository.FileStoreState;
import org.dcache.pool.repository.DuplicateEntryException;
import org.dcache.pool.repository.FileStore;
import org.dcache.pool.repository.ReplicaRecord;
Expand Down Expand Up @@ -174,8 +175,13 @@ public void remove(PnfsId id) throws CacheException {
}

@Override
public boolean isOk() {
return _fileStore.isOk() && super.isOk();
public FileStoreState isOk() {
if (_fileStore.isOk() == FileStoreState.OK && super.isOk() == FileStoreState.OK){
return FileStoreState.OK;
}
else {
return FileStoreState.FAILED;
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.List;
import java.util.Set;
import java.util.stream.Stream;
import org.dcache.pool.repository.FileStoreState;
import org.dcache.pool.repository.DuplicateEntryException;
import org.dcache.pool.repository.FileStore;
import org.dcache.pool.repository.ReplicaRecord;
Expand Down Expand Up @@ -180,18 +181,18 @@ protected void deleteIfExists(Path path) throws DiskErrorCacheException {
}

@Override
public synchronized boolean isOk() {
if (!_fileStore.isOk()) {
return false;
public synchronized FileStoreState isOk() {
if (_fileStore.isOk() == FileStoreState.FAILED) {
return FileStoreState.FAILED;
}
Path tmp = _metadir.resolve(".repository_is_ok");
try {
Files.deleteIfExists(tmp);
Files.createFile(tmp);
return true;
return FileStoreState.OK;
} catch (IOException e) {
LOGGER.error("Failed to touch " + tmp + ": " + messageOrClassName(e), e);
return false;
return FileStoreState.FAILED;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.bson.Document;
import org.dcache.pool.repository.FileStoreState;
import org.dcache.pool.repository.DuplicateEntryException;
import org.dcache.pool.repository.FileStore;
import org.dcache.pool.repository.ReplicaRecord;
Expand Down Expand Up @@ -111,7 +112,7 @@ public class MongoDbMetadataRepository implements ReplicaStore, EnvironmentAware
/**
* Flag, which indicates client connection status.
*/
private volatile boolean isOk;
private volatile FileStoreState dIskFailerState;

/**
* {@link FileStore} used to store data files.
Expand All @@ -126,7 +127,7 @@ public MongoDbMetadataRepository(FileStore fileStore, Path ignored, String poolN
boolean isReadOnly) {
this.fileStore = fileStore;
this.pool = poolName;
this.isOk = false;
this.dIskFailerState = FileStoreState.FAILED;
}

@Override
Expand Down Expand Up @@ -223,7 +224,7 @@ public void remove(PnfsId id) throws CacheException {
deleteIfExists(id);

} catch (IOException | MongoException e) {
isOk = false;
dIskFailerState = FileStoreState.FAILED;
throw new DiskErrorCacheException(
"Failed to remove " + id + ": " + messageOrClassName(e), e);
}
Expand All @@ -247,8 +248,8 @@ private void deleteIfExists(PnfsId id) {
}

@Override
public boolean isOk() {
return isOk;
public FileStoreState isOk() {
return dIskFailerState;
}

@Override
Expand Down Expand Up @@ -291,13 +292,13 @@ public void setEnvironment(Map<String, Object> environment) {
@Override
public void serverOpening(ServerOpeningEvent event) {
LOGGER.info("Connected to server {}", event.getServerId());
isOk = true;
dIskFailerState = FileStoreState.OK;
}

@Override
public void serverClosed(ServerClosedEvent event) {
LOGGER.info("Lost connection with server {}", event.getServerId());
isOk = false;
dIskFailerState = FileStoreState.FAILED;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.dcache.alarms.PredefinedAlarm;
import org.dcache.pool.FaultAction;
import org.dcache.pool.repository.Account;
import org.dcache.pool.repository.FileStoreState;
import org.dcache.pool.repository.ReplicaStore;
import org.dcache.pool.repository.SpaceRecord;
import org.slf4j.Logger;
Expand Down Expand Up @@ -68,7 +69,7 @@ public void run() {
case CLOSED:
break;
case OPEN:
if (!_replicaStore.isOk()) {
if (_replicaStore.isOk() == FileStoreState.FAILED) {
_repository.fail(FaultAction.DISABLED, "I/O test failed");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Set;
import java.util.stream.Stream;
import org.dcache.namespace.FileAttribute;
import org.dcache.pool.repository.FileStoreState;
import org.dcache.pool.repository.DuplicateEntryException;
import org.dcache.pool.repository.FileStore;
import org.dcache.pool.repository.ReplicaRecord;
Expand Down Expand Up @@ -235,8 +236,8 @@ public Set<PnfsId> index(IndexOption... options) {
}

@Override
public boolean isOk() {
return true;
public FileStoreState isOk() {
return FileStoreState.OK;
}

@Override
Expand Down

0 comments on commit 862963e

Please sign in to comment.