@@ -135,10 +135,9 @@ struct Config {
135135};
136136
137137// fill the CAS with random data of specified tree depth and children numbers.
138- static void fillData (ObjectStore &CAS, const Config &Conf) {
138+ static void fillData (ObjectStore &CAS, ActionCache &AC, const Config &Conf) {
139139 ExitOnError ExitOnErr (" llvm-cas-test fill data: " );
140140 DefaultThreadPool ThreadPool (hardware_concurrency ());
141- std::atomic<uint64_t > NumCreated = 0 ;
142141 for (size_t I = 0 ; I != Conf.NumShards ; ++I) {
143142 ThreadPool.async ([&] {
144143 std::vector<ObjectRef> Refs;
@@ -163,8 +162,11 @@ static void fillData(ObjectStore &CAS, const Config &Conf) {
163162 auto Ref = ExitOnErr (CAS.store (Parent, Data));
164163 Created.push_back (Ref);
165164 }
166- ++NumCreated;
167165 }
166+ // Put a self mapping in action cache to avoid cache poisoning.
167+ if (!Created.empty ())
168+ ExitOnErr (
169+ AC.put (CAS.getID (Created.back ()), CAS.getID (Created.back ())));
168170 Refs.swap (Created);
169171 }
170172 });
@@ -179,7 +181,7 @@ static int genData() {
179181 Conf.init ();
180182
181183 auto DB = ExitOnErr (cas::createOnDiskUnifiedCASDatabases (CASPath));
182- fillData (*DB.first , Conf);
184+ fillData (*DB.first , *DB. second , Conf);
183185
184186 return 0 ;
185187}
@@ -203,10 +205,11 @@ static int runOneTest(const char *Argv0) {
203205 }
204206
205207 auto DB = ExitOnErr (cas::createOnDiskUnifiedCASDatabases (CASPath));
206- auto &CAS = DB.first ;
208+ auto &CAS = *DB.first ;
209+ auto &AC = *DB.second ;
207210
208211 // Size limit in MB.
209- ExitOnErr (CAS-> setSizeLimit (SizeLimit * 1024 * 1024 ));
212+ ExitOnErr (CAS. setSizeLimit (SizeLimit * 1024 * 1024 ));
210213 if (Conf.Settings & Fork) {
211214 // fill data using sub processes.
212215 std::string MainExe = sys::fs::getMainExecutable (Argv0, &CASPath);
@@ -236,12 +239,12 @@ static int runOneTest(const char *Argv0) {
236239
237240 } else {
238241 // in-process fill data.
239- fillData (* CAS, Conf);
242+ fillData (CAS, AC , Conf);
240243 }
241244
242245 // validate and prune in the end.
243- ExitOnErr (CAS-> validate (true ));
244- ExitOnErr (CAS-> pruneStorageData ());
246+ ExitOnErr (CAS. validate (true ));
247+ ExitOnErr (CAS. pruneStorageData ());
245248
246249 return 0 ;
247250}
0 commit comments