Skip to content

Commit

Permalink
Added random seed to objcfg to make server shuffling reproducable
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuerstchen committed Aug 25, 2022
1 parent 92bd329 commit 839cfdb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/XrdEc/XrdEcObjCfg.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <vector>
#include <sstream>
#include <iomanip>
#include <chrono>

namespace XrdEc
{
Expand Down Expand Up @@ -46,6 +47,7 @@ namespace XrdEc
nomtfile( nomtfile )
{
digest = usecrc32c ? crc32c : isal_crc32;
seed = std::chrono::system_clock::now().time_since_epoch().count();
}

ObjCfg( const ObjCfg &objcfg ) : obj( objcfg.obj ),
Expand All @@ -59,7 +61,8 @@ namespace XrdEc
plgr( objcfg.plgr ),
plgrReplace(objcfg.plgrReplace),
digest( objcfg.digest ),
nomtfile( objcfg.nomtfile )
nomtfile( objcfg.nomtfile ),
seed( objcfg.seed )
{
}

Expand Down Expand Up @@ -105,6 +108,8 @@ namespace XrdEc
uint32_t (*digest)(uint32_t, void const*, size_t);

bool nomtfile;

uint64_t seed; // the seed used for e.g. server shuffling, default set to current time
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/XrdEc/XrdEcStrmWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ namespace XrdEc
//-------------------------------------------------------------------------
// Shuffle the servers so every block has a different placement
//-------------------------------------------------------------------------
static std::default_random_engine random_engine( std::chrono::system_clock::now().time_since_epoch().count() );
static std::default_random_engine random_engine( objcfg.seed );
std::shared_ptr<sync_queue<size_t>> servers = std::make_shared<sync_queue<size_t>>();
std::vector<size_t> zipid( dataarchs.size() );
std::iota( zipid.begin(), zipid.end(), 0 );
Expand Down
2 changes: 1 addition & 1 deletion tests/XrdEcTests/MicroTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class MicroTest: public CppUnit::TestCase
InitRepair(usecrc32c);
uint64_t seed2 = std::chrono::system_clock::now().time_since_epoch().count();

XrdCl::DefaultEnv::GetLog()->Debug(XrdCl::XRootDMsg, "Random Seed FileGen: %d, Random Seed Corruption: %d" , seed, seed2);
XrdCl::DefaultEnv::GetLog()->Debug(XrdCl::XRootDMsg, "Random Seed FileGen: %d, Random Seed Corruption: %d, Random Seed ObjCfg: %d" , seed, seed2, objcfg->seed);

// run the test

Expand Down

0 comments on commit 839cfdb

Please sign in to comment.