Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
Expand All @@ -32,10 +37,6 @@
import javax.jcr.RepositoryException;

import org.apache.commons.io.IOUtils;
import org.apache.jackrabbit.oak.spi.blob.fs.FileSystem;
import org.apache.jackrabbit.oak.spi.blob.fs.FileSystemException;
import org.apache.jackrabbit.oak.spi.blob.fs.FileSystemResource;
import org.apache.jackrabbit.oak.spi.blob.fs.local.LocalFileSystem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -146,7 +147,7 @@
/**
* File that holds the data identifiers if delayDelete is enabled.
*/
private FileSystemResource identifiersToDeleteFile = null;
private File identifiersToDeleteFile = null;

private Thread deleteDelayedIdentifiersTaskThread;

Expand Down Expand Up @@ -328,11 +329,7 @@
*/
public void init(String homeDir) throws RepositoryException {
if (delayedDelete) {
// First initialize the identifiersToDeleteFile
LocalFileSystem fileSystem = new LocalFileSystem();
fileSystem.setRoot(new File(homeDir));
identifiersToDeleteFile = new FileSystemResource(fileSystem, FileSystem.SEPARATOR
+ IDENTIFIERS_TO_DELETE_FILE_KEY);
identifiersToDeleteFile = Paths.get(homeDir,IDENTIFIERS_TO_DELETE_FILE_KEY).toFile();
}
moveDataTaskThread = new Thread(new MoveDataTask(),
"Jackrabbit-MulitDataStore-MoveDataTaskThread");
Expand All @@ -341,26 +338,21 @@
log.info("MultiDataStore-MoveDataTask thread started; first run scheduled at "
+ moveDataTaskNextRun.getTime());
if (delayedDelete) {
try {
// Run on startup the DeleteDelayedIdentifiersTask only if the
// file exists and modify date is older than the
// delayedDeleteSleep timeout ...
if (identifiersToDeleteFile != null
&& identifiersToDeleteFile.exists()
&& (identifiersToDeleteFile.lastModified() + (delayedDeleteSleep * 1000)) < System
.currentTimeMillis()) {
deleteDelayedIdentifiersTaskThread = new Thread(
//Start immediately ...
new DeleteDelayedIdentifiersTask(0L),
"Jackrabbit-MultiDataStore-DeleteDelayedIdentifiersTaskThread");
deleteDelayedIdentifiersTaskThread.setDaemon(true);
deleteDelayedIdentifiersTaskThread.start();
log.info("Old entries in the " + IDENTIFIERS_TO_DELETE_FILE_KEY
+ " File found. DeleteDelayedIdentifiersTask-Thread started now.");
}
} catch (FileSystemException e) {
throw new RepositoryException("I/O error while reading from '"
+ identifiersToDeleteFile.getPath() + "'", e);
// Run on startup the DeleteDelayedIdentifiersTask only if the
// file exists and modify date is older than the
// delayedDeleteSleep timeout ...
if (identifiersToDeleteFile != null

Check warning on line 344 in oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/MultiDataStore.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this if statement with the enclosing one.

See more on https://sonarcloud.io/project/issues?id=org.apache.jackrabbit%3Ajackrabbit-oak&issues=AZ1PASvfoMApxTvofMz7&open=AZ1PASvfoMApxTvofMz7&pullRequest=2830
&& identifiersToDeleteFile.exists()
&& (identifiersToDeleteFile.lastModified() + (delayedDeleteSleep * 1000)) < System
.currentTimeMillis()) {
deleteDelayedIdentifiersTaskThread = new Thread(
//Start immediately ...
new DeleteDelayedIdentifiersTask(0L),
"Jackrabbit-MultiDataStore-DeleteDelayedIdentifiersTaskThread");
deleteDelayedIdentifiersTaskThread.setDaemon(true);
deleteDelayedIdentifiersTaskThread.start();
log.info("Old entries in the " + IDENTIFIERS_TO_DELETE_FILE_KEY
+ " File found. DeleteDelayedIdentifiersTask-Thread started now.");
}
}
}
Expand Down Expand Up @@ -491,10 +483,7 @@
private boolean writeDelayedDataIdentifier(DataIdentifier identifier) {
BufferedWriter writer = null;
try {
File identifierFile = new File(
((LocalFileSystem) identifiersToDeleteFile.getFileSystem()).getPath(),
identifiersToDeleteFile.getPath());
writer = new BufferedWriter(new FileWriter(identifierFile, true));
writer = new BufferedWriter(new FileWriter(identifiersToDeleteFile, true));
writer.write(identifier.toString());
return true;
} catch (Exception e) {
Expand All @@ -516,7 +505,7 @@
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new OutputStreamWriter(
identifiersToDeleteFile.getOutputStream()));
new FileOutputStream(identifiersToDeleteFile)));
writer.write("");
return true;
} catch (Exception e) {
Expand Down Expand Up @@ -665,7 +654,7 @@
try {
int deleted = 0;
reader = new BufferedReader(new InputStreamReader(
identifiersToDeleteFile.getInputStream()));
new FileInputStream(identifiersToDeleteFile)));
while (true) {
String s = reader.readLine();
if (s == null || s.equals("")) {
Expand All @@ -691,8 +680,8 @@
log.info("Deleted " + deleted + " DataRecords from the primary data store.");
if (problemIdentifiers.isEmpty()) {
try {
identifiersToDeleteFile.delete();
} catch (FileSystemException e) {
Files.delete(identifiersToDeleteFile.toPath());
} catch (IOException e) {
log.warn("Unable to delete the " + IDENTIFIERS_TO_DELETE_FILE_KEY
+ " File.");
if (!purgeDelayedDeleteFile()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,6 @@ public interface FileSystem {
*/
OutputStream getOutputStream(String filePath) throws FileSystemException;

/**
* Creates the folder named by this path, including any necessary but
* nonexistent parent folders. Note that if this operation fails it
* may have succeeded in creating some of the necessary parent folders.
*
* @param folderPath the path of the folder to be created.
* @throws FileSystemException if a file system entry denoted by path
* already exists or if another error occurs.
*/
void createFolder(String folderPath) throws FileSystemException;

/**
* Tests whether the file system entry denoted by this path exists.
*
Expand All @@ -107,16 +96,6 @@ public interface FileSystem {
*/
boolean isFile(String path) throws FileSystemException;

/**
* Tests whether the file system entry denoted by this path exists and
* is a folder.
*
* @param path the path of a file system entry.
* @return true if the file system entry at path is a folder; false otherwise.
* @throws FileSystemException
*/
boolean isFolder(String path) throws FileSystemException;

/**
* Tests whether the file system entry denoted by this path has child entries.
*
Expand Down Expand Up @@ -173,18 +152,6 @@ public interface FileSystem {
*/
String[] listFiles(String folderPath) throws FileSystemException;

/**
* Returns an array of strings naming the folders in the folder
* denoted by this path.
*
* @param folderPath the path of the folder whose contents is to be listed.
* @return an array of strings naming the folders in the folder
* denoted by this path.
* @throws FileSystemException if this path does not denote a folder or if
* another error occurs.
*/
String[] listFolders(String folderPath) throws FileSystemException;

/**
* Deletes the file denoted by this path.
*
Expand All @@ -193,15 +160,4 @@ public interface FileSystem {
* another error occurs.
*/
void deleteFile(String filePath) throws FileSystemException;

/**
* Deletes the folder denoted by this path. Any contents of this folder
* (folders and files) will be deleted recursively.
*
* @param folderPath the path of the folder to be deleted.
* @throws FileSystemException if this path does not denote a folder or if
* another error occurs.
*/
void deleteFolder(String folderPath) throws FileSystemException;

}
Loading
Loading