Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(ChunkTrash): Apply sugestions from PR
Browse files Browse the repository at this point in the history
ictus4u committed Nov 4, 2024
1 parent 8978bb6 commit 16c6a2d
Showing 5 changed files with 37 additions and 31 deletions.
27 changes: 11 additions & 16 deletions src/chunkserver/chunkserver-common/chunk_trash_manager.h
Original file line number Diff line number Diff line change
@@ -97,27 +97,22 @@ class ChunkTrashManager {
*/
void collectGarbage();

/**
* @brief Reloads the configuration for the trash manager.
*/
/// Reloads the configuration for the trash manager.
void reloadConfig();

// Deleted to enforce singleton behavior
ChunkTrashManager(
const ChunkTrashManager &) = delete; ///< Copy constructor is deleted.
ChunkTrashManager &operator=(
const ChunkTrashManager &) = delete; ///< Copy assignment operator is deleted.
ChunkTrashManager(
ChunkTrashManager &&) = delete; ///< Move constructor is deleted.
ChunkTrashManager &operator=(
ChunkTrashManager &&) = delete; ///< Move assignment operator is deleted.
~ChunkTrashManager() = default; ///< Destructor is explicitly defaulted.
ChunkTrashManager(const ChunkTrashManager &) = delete;
ChunkTrashManager &operator=(const ChunkTrashManager &) = delete;
ChunkTrashManager(ChunkTrashManager &&) = delete;
ChunkTrashManager &operator=(ChunkTrashManager &&) = delete;

~ChunkTrashManager() = default; ///< Destructor

private:
// Constructor is private to enforce singleton behavior
ChunkTrashManager() = default; ///< Default constructor.
/// Constructor is private to enforce singleton behavior
ChunkTrashManager() = default;

static ChunkTrashManager::ImplentationPtr pImpl; ///< Pointer to the
// implementation details.
/// Pointer to the singleton instance of the trash manager implementation.
static ChunkTrashManager::ImplentationPtr pImpl;

};
Original file line number Diff line number Diff line change
@@ -72,8 +72,7 @@ class ChunkTrashManagerImpl : public IChunkTrashManagerImpl {
* @param timeLimit The cutoff time; files older than this will be removed.
* @param bulkSize The number of files to process in a batch operation.
*/
void removeExpiredFiles(const std::time_t &timeLimit, size_t
bulkSize = 0);
void removeExpiredFiles(const std::time_t &timeLimit, size_t bulkSize = 0);

/**
* @brief Removes a set of specified files from the trash.
4 changes: 4 additions & 0 deletions src/chunkserver/chunkserver-common/cmr_disk.cc
Original file line number Diff line number Diff line change
@@ -205,6 +205,8 @@ int CmrDisk::unlinkChunk(IChunk *chunk) {
metaDiskPath,
deletionTime);
if (result != SAUNAFS_STATUS_OK) {
safs_pretty_errlog(LOG_ERR, "Error moving meta file to trash: %s, error: %d",
metaFile.c_str(), result);
return result;
}

@@ -213,6 +215,8 @@ int CmrDisk::unlinkChunk(IChunk *chunk) {
dataDiskPath,
deletionTime);
if (result != SAUNAFS_STATUS_OK) {
safs_pretty_errlog(LOG_ERR, "Error moving data file to trash: %s, error: %d",
dataFile.c_str(), result);
return result;
}
} else {
7 changes: 5 additions & 2 deletions src/chunkserver/hddspacemgr.cc
Original file line number Diff line number Diff line change
@@ -2622,11 +2622,14 @@ int hddInit() {

{
std::lock_guard disksLockGuard(gDisksMutex);
for (const auto& disk : gDisks) {
for (const auto &disk: gDisks) {
safs_pretty_syslog(LOG_INFO, "hdd space manager: disk to scan: %s",
disk->getPaths().c_str());
ChunkTrashManager::instance().init(disk->metaPath());
if(disk->metaPath() != disk->dataPath()) {
if (disk->isZonedDevice()) {
continue;
}
if (disk->metaPath() != disk->dataPath()) {
ChunkTrashManager::instance().init(disk->dataPath());
}
}
27 changes: 16 additions & 11 deletions tests/test_suites/ShortSystemTests/test_unlink_trash.sh
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ CHUNKSERVERS=4 \
MOUNT_EXTRA_CONFIG="sfscachemode=NEVER" \
MASTER_EXTRA_CONFIG="CHUNKS_LOOP_MIN_TIME = 1`
`|CHUNKS_LOOP_MAX_CPU = 90`
`|OPERATIONS_DELAY_INIT = 0" \
`|OPERATIONS_DELAY_INIT = 1" \
CHUNKSERVER_EXTRA_CONFIG="CHUNK_TRASH_ENABLED=1`
`|CHUNK_TRASH_EXPIRATION_SECONDS=55" \
USE_RAMDISK="YES" \
@@ -19,18 +19,25 @@ CHUNKSERVERS=4 \
# Create a file consising of a couple of chunks and remove it
file="${info[mount0]}/file"
xorfile="${info[mount0]}/xorfile"
touch "$file" "$xorfile"
saunafs setgoal 3 "$file"
saunafs setgoal xor3 "$xorfile"
dd if=/dev/zero of="$file" bs=1MiB count=130
dd if=/dev/zero of="$xorfile" bs=1MiB count=130
saunafs settrashtime 0 "$file" "$xorfile"
touch "${file}" "${xorfile}"
saunafs setgoal 3 "${file}"
saunafs setgoal xor3 "${xorfile}"
test_file_size_mb=130
dd if=/dev/zero of="${file}" bs=1MiB count=130
dd if=/dev/zero of="${xorfile}" bs=1MiB count=130
saunafs settrashtime 0 "${file}" "${xorfile}"

files_count=2
chunk_size_mb=64
chunks_count=$(( (test_file_size_mb / chunk_size_mb + \
(test_file_size_mb % chunk_size_mb ? 1 : 0) ) * files_count ))

waiting_timeout="3 minutes"

# Wait for the chunks to be replicated
## TODO: Remove magic number 6
if ! wait_for '[ $(chunks_replicated_count) -eq 6 ]' "${waiting_timeout}"; then
if ! wait_for '[ "$(chunks_replicated_count)" -eq "${chunks_count}" ]' \
"${waiting_timeout}";
then
test_add_failure $'The chunks replication timed out'
fi

@@ -46,8 +53,6 @@ fi

# Ensure the "unlinked" files are trashed
trashed_chunks_count=$(find_all_trashed_chunks | wc -l)
## TODO: Remove the below debug call
find_all_trashed_chunks
echo "Trashed chunks count: ${trashed_chunks_count}"
if [ "${trashed_chunks_count}" -eq 0 ]; then
test_add_failure $'The removed chunks were not moved to the trash folder'

0 comments on commit 16c6a2d

Please sign in to comment.