Class DatabaseBasedActiveBitPreservation
- java.lang.Object
-
- dk.netarkivet.archive.arcrepository.bitpreservation.DatabaseBasedActiveBitPreservation
-
- All Implemented Interfaces:
ActiveBitPreservation
,CleanupIF
public final class DatabaseBasedActiveBitPreservation extends Object implements ActiveBitPreservation, CleanupIF
The database based active bit preservation. This is the alternative to the FileBasedActiveBitPreservation.A database is used to handle the bitpreservation.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMissingFilesToAdminData(String... filenames)
Old method, which refers to the checksum replica part of admin data.void
changeStateForAdminData(String filename)
This should reestablish the state for the file.void
cleanup()
Method for cleaning up this instance.void
close()
Method for closing the running instance of this class.void
findChangedFiles(Replica replica)
The method is used to update the checksum for all the files in a replica.void
findMissingFiles(Replica replica)
This method retrieves the filelist for the replica, and then it updates the database with this list of filenames.Iterable<String>
getChangedFiles(Replica replica)
This method retrieves the name of all the files which has a wrong checksum for the replica.Iterable<String>
getChangedFilesForAdminData()
Old method, which refers to the checksum replica part of admin data.Date
getDateForChangedFiles(Replica replica)
This method retrieves the date for the latest checksum update was performed for the replica.Date
getDateForMissingFiles(Replica replica)
This method retrieves the date for the latest filelist update was performed for the replica.static DatabaseBasedActiveBitPreservation
getInstance()
Method for retrieving the current instance of this class.Iterable<String>
getMissingFiles(Replica replica)
This method retrieves the name of all the files which are missing for the given replica.Iterable<String>
getMissingFilesForAdminData()
Old method, which refers to the checksum replica part of admin data.long
getNumberOfChangedFiles(Replica replica)
The method calculates the number of files which has a wrong checksum for the replica.long
getNumberOfFiles(Replica replica)
This method finds the number of files which are known to be in the archive of a specific replica.long
getNumberOfMissingFiles(Replica replica)
This method calculates the number of files which are not found in the given replica.PreservationState
getPreservationState(String filename)
Method for retrieving the FilePreservationState for a specific file.Map<String,PreservationState>
getPreservationStateMap(String... filenames)
Method for retrieving the FilePreservationState for a list of files.void
replaceChangedFile(Replica replica, String filename, String credentials, String checksum)
Check that the checksum of the file is indeed different to the value in admin data and reference replica.void
uploadMissingFiles(Replica replica, String... filenames)
This method is used to upload missing files to a replica.
-
-
-
Method Detail
-
getInstance
public static DatabaseBasedActiveBitPreservation getInstance()
Method for retrieving the current instance of this class.- Returns:
- The instance.
-
getNumberOfChangedFiles
public long getNumberOfChangedFiles(Replica replica) throws ArgumentNotValid
The method calculates the number of files which has a wrong checksum for the replica. This simple counts all the entries in the replicafileinfo table for the replica where the filelist_status is set to CORRUPT.- Specified by:
getNumberOfChangedFiles
in interfaceActiveBitPreservation
- Parameters:
replica
- The replica for which to count the number of changed files.- Returns:
- The number of files for the replica where the checksum does not correspond to the checksum of the same file in the other replicas.
- Throws:
ArgumentNotValid
- If the replica is null.
-
getChangedFiles
public Iterable<String> getChangedFiles(Replica replica) throws ArgumentNotValid
This method retrieves the name of all the files which has a wrong checksum for the replica. It simple returns the filename of all the entries in the replicafileinfo table for the replica where the filelist_status is set to CORRUPT.- Specified by:
getChangedFiles
in interfaceActiveBitPreservation
- Parameters:
replica
- The replica for which the changed files should be found.- Returns:
- The names of files in the replica where the checksum does not correspond to the checksum of the same file in the other replicas.
- Throws:
ArgumentNotValid
- If the replica is null.
-
getNumberOfMissingFiles
public long getNumberOfMissingFiles(Replica replica) throws ArgumentNotValid
This method calculates the number of files which are not found in the given replica. This simple counts all the entries in the replicafileinfo table for the replica where the filelist_status is set to MISSING.- Specified by:
getNumberOfMissingFiles
in interfaceActiveBitPreservation
- Parameters:
replica
- The replica for which to count the number of missing files.- Returns:
- The number of files which is missing in the replica.
- Throws:
ArgumentNotValid
- If the replica is null.
-
getMissingFiles
public Iterable<String> getMissingFiles(Replica replica) throws ArgumentNotValid
This method retrieves the name of all the files which are missing for the given replica. It simple returns the filename of all the entries in the replicafileinfo table for the replica where the filelist_status is set to MISSING.- Specified by:
getMissingFiles
in interfaceActiveBitPreservation
- Parameters:
replica
- The replica for which the missing files should be found.- Returns:
- The names of files in the replica which are missing.
- Throws:
ArgumentNotValid
- If the replica is null.
-
getDateForChangedFiles
public Date getDateForChangedFiles(Replica replica) throws ArgumentNotValid
This method retrieves the date for the latest checksum update was performed for the replica. This means the date for the latest the replica has calculated the checksum of all the files within its archive.This method does not call out to the replicas. It only contacts the local database.
- Specified by:
getDateForChangedFiles
in interfaceActiveBitPreservation
- Parameters:
replica
- The replica for which the date for last checksum update should be retrieved.- Returns:
- The date for the last time the checksums has been update. If the checksum update has never occurred, then a null is returned.
- Throws:
ArgumentNotValid
- If the replica is null.
-
getDateForMissingFiles
public Date getDateForMissingFiles(Replica replica) throws ArgumentNotValid
This method retrieves the date for the latest filelist update was performed for the replica. This means the date for the latest the replica has retrieved the list of all the files within the archive.This method does not call out to the replicas. It only contacts the local database.
- Specified by:
getDateForMissingFiles
in interfaceActiveBitPreservation
- Parameters:
replica
- The replica for which the date for last filelist update should be retrieved.- Returns:
- The date for the last time the filelist has been update. If the filelist update has never occurred, then a null is returned.
- Throws:
ArgumentNotValid
- If the replica is null.
-
findChangedFiles
public void findChangedFiles(Replica replica) throws ArgumentNotValid
The method is used to update the checksum for all the files in a replica. The checksum for the replica is retrieved through GetAllChecksumMessages. This will take a very large amount of time for the bitarchive, but a more limited amount of time for the checksumarchive.The corresponding replicafileinfo entries in the database for the retrieved checksum results will be updated. Then a checksum update will be performed to check for corrupted replicafileinfo.
Each replica can only be updated once at the time.
- Specified by:
findChangedFiles
in interfaceActiveBitPreservation
- Parameters:
replica
- The replica to find the changed files for.- Throws:
ArgumentNotValid
- If the replica is null.
-
findMissingFiles
public void findMissingFiles(Replica replica) throws ArgumentNotValid
This method retrieves the filelist for the replica, and then it updates the database with this list of filenames. Each replica can only be updated once at the time.- Specified by:
findMissingFiles
in interfaceActiveBitPreservation
- Parameters:
replica
- The replica to find the missing files for.- Throws:
ArgumentNotValid
- If the replica is null.
-
getPreservationState
public PreservationState getPreservationState(String filename) throws ArgumentNotValid
Method for retrieving the FilePreservationState for a specific file.- Specified by:
getPreservationState
in interfaceActiveBitPreservation
- Parameters:
filename
- The name of the file for whom the FilePreservationState should be retrieved.- Returns:
- The FilePreservationState for the file.
- Throws:
ArgumentNotValid
- If the filename is null or the empty string.
-
getPreservationStateMap
public Map<String,PreservationState> getPreservationStateMap(String... filenames) throws ArgumentNotValid
Method for retrieving the FilePreservationState for a list of files.- Specified by:
getPreservationStateMap
in interfaceActiveBitPreservation
- Parameters:
filenames
- The list of filenames whose FilePreservationState should be retrieved.- Returns:
- A mapping between the filenames and their FilePreservationState.
- Throws:
ArgumentNotValid
- If the list of filenames are null.
-
getNumberOfFiles
public long getNumberOfFiles(Replica replica) throws ArgumentNotValid
This method finds the number of files which are known to be in the archive of a specific replica. This method will not go out to the replica, but only contact the local database. The number of files in the replica is retrieved from the database by counting the amount of files in the replicafileinfo table which belong to the replica and which has the filelist_status set to OK.- Specified by:
getNumberOfFiles
in interfaceActiveBitPreservation
- Parameters:
replica
- The replica for which the number of files should be counted.- Returns:
- The number of files for a specific replica.
- Throws:
ArgumentNotValid
- If the replica is null.
-
replaceChangedFile
public void replaceChangedFile(Replica replica, String filename, String credentials, String checksum) throws ArgumentNotValid
Check that the checksum of the file is indeed different to the value in admin data and reference replica. If so, remove missing file and upload it from reference replica to this replica.- Specified by:
replaceChangedFile
in interfaceActiveBitPreservation
- Parameters:
replica
- The replica to restore file tofilename
- The name of the filecredentials
- The credentials used to perform this replace operationchecksum
- The known bad checksum. Only a file with this bad checksum is attempted repaired.- Throws:
ArgumentNotValid
- If any of the arguments are not valid.
-
uploadMissingFiles
public void uploadMissingFiles(Replica replica, String... filenames) throws ArgumentNotValid, IOFailure
This method is used to upload missing files to a replica. For each file a good version of this file is found, and it is reestablished on the replicas where it is missing.- Specified by:
uploadMissingFiles
in interfaceActiveBitPreservation
- Parameters:
replica
- The replica where the files are missing.filenames
- The names of the files which are missing in the given replica.- Throws:
ArgumentNotValid
- If the replica or list of filenames is null, or if the list of filenames is empty.IOFailure
- If some files could not be established.
-
changeStateForAdminData
public void changeStateForAdminData(String filename) throws ArgumentNotValid, NotImplementedException
This should reestablish the state for the file.- Specified by:
changeStateForAdminData
in interfaceActiveBitPreservation
- Parameters:
filename
- The name of the file to change the state for.- Throws:
ArgumentNotValid
- If the filename is invalid.NotImplementedException
- This will not be implemented.
-
getMissingFilesForAdminData
public Iterable<String> getMissingFilesForAdminData() throws NotImplementedException
Old method, which refers to the checksum replica part of admin data.- Specified by:
getMissingFilesForAdminData
in interfaceActiveBitPreservation
- Returns:
- Nothing, since it always throws an exception.
- Throws:
NotImplementedException
- This method will not be implemented.
-
getChangedFilesForAdminData
public Iterable<String> getChangedFilesForAdminData() throws NotImplementedException
Old method, which refers to the checksum replica part of admin data.- Specified by:
getChangedFilesForAdminData
in interfaceActiveBitPreservation
- Returns:
- Nothing, since it always throws an exception.
- Throws:
NotImplementedException
- This method will not be implemented.
-
addMissingFilesToAdminData
public void addMissingFilesToAdminData(String... filenames) throws ArgumentNotValid, NotImplementedException
Old method, which refers to the checksum replica part of admin data.- Specified by:
addMissingFilesToAdminData
in interfaceActiveBitPreservation
- Parameters:
filenames
- The list of filenames which should be added to admin data.- Throws:
NotImplementedException
- This method will not be implemented.ArgumentNotValid
- If filenames invalid.
-
close
public void close()
Method for closing the running instance of this class.
-
-