|
17 | 17 | #include "rocksdb/env.h" |
18 | 18 | #include "rocksdb/options.h" |
19 | 19 | #include "rocksdb/status.h" |
| 20 | +#include "util/random.h" |
20 | 21 |
|
21 | 22 | namespace ROCKSDB_NAMESPACE { |
22 | 23 |
|
@@ -189,22 +190,50 @@ Status CloudEnvImpl::FindObsoleteDbid( |
189 | 190 | return st; |
190 | 191 | } |
191 | 192 |
|
| 193 | +std::string CloudEnvImpl::GetScratchDirectory() const { |
| 194 | + const char* env = getenv("TMPDIR"); |
| 195 | + if (env != nullptr) { |
| 196 | + return std::string(env); |
| 197 | + } else { |
| 198 | +#ifdef _WIN32 |
| 199 | + env = getenv("TEMP"); |
| 200 | + if (env == nullptr) { |
| 201 | + env = getenv("TMP"); |
| 202 | + } |
| 203 | + if (env != nullptr) { |
| 204 | + return std::string(env); |
| 205 | + } else { |
| 206 | + return "c:\\tmp"; |
| 207 | + } |
| 208 | +#else |
| 209 | + return "/tmp"; |
| 210 | +#endif |
| 211 | + } |
| 212 | +} |
| 213 | + |
| 214 | +std::string CloudEnvImpl::GetScratchFile() const { |
| 215 | + int64_t current_time = 0; |
| 216 | + auto s = base_env_->GetCurrentTime(¤t_time); |
| 217 | + if (!s.ok()) { |
| 218 | + current_time = static_cast<int64_t>(std::time(0)); |
| 219 | + } |
| 220 | + Random rand(static_cast<uint32_t>(current_time)); |
| 221 | + const std::string scratch = GetScratchDirectory(); |
| 222 | + return TempFileName(scratch, rand.Next()); |
| 223 | +} |
| 224 | + |
192 | 225 | // |
193 | 226 | // For each of the dbids in the list, extract the entire list of |
194 | 227 | // parent dbids. |
195 | 228 | Status CloudEnvImpl::extractParents(const std::string& bucket_name_prefix, |
196 | 229 | const DbidList& dbid_list, |
197 | 230 | DbidParents* parents) { |
198 | 231 | const std::string delimiter(DBID_SEPARATOR); |
199 | | - // use current time as seed for random generator |
200 | | - std::srand(static_cast<unsigned int>(std::time(0))); |
201 | | - const std::string random = std::to_string(std::rand()); |
202 | | - const std::string scratch(SCRATCH_LOCAL_DIR); |
| 232 | + auto localfile = GetScratchFile(); |
203 | 233 | Status st; |
204 | 234 | for (auto iter = dbid_list.begin(); iter != dbid_list.end(); ++iter) { |
205 | 235 | // download IDENTITY |
206 | 236 | std::string cloudfile = iter->second + "/IDENTITY"; |
207 | | - std::string localfile = scratch + "/.rockset_IDENTITY." + random; |
208 | 237 | st = GetCloudEnvOptions().storage_provider->GetCloudObject( |
209 | 238 | bucket_name_prefix, cloudfile, localfile); |
210 | 239 | if (!st.ok() && !st.IsNotFound()) { |
|
0 commit comments