Commit a13e1e0d authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[3671] Addressed second round of review comments.

Simplified the method which loads leases from the CSV file.
parent 52bd9f4d
...@@ -481,57 +481,35 @@ loadLeasesFromFiles(const std::string& filename, ...@@ -481,57 +481,35 @@ loadLeasesFromFiles(const std::string& filename,
StorageType& storage) { StorageType& storage) {
storage.clear(); storage.clear();
for (int i = 2; i >= 0; --i) { // Load the leasefile.completed, if exists.
bool completed_exists = false; lease_file.reset(new LeaseFileType(std::string(filename + ".completed")));
if (lease_file->exists()) {
LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
MAX_LEASE_ERRORS);
// Initialize the name of the lease file to parse. For the } else {
// first two loops we're going to append .2 and .1 to the // If the leasefile.completed doesn't exist, let's load the leases
// lease file name, unless the file with the .completed // from leasefile.2 and leasefile.1, if they exist.
// postfix exists. lease_file.reset(new LeaseFileType(std::string(filename + ".2")));
std::ostringstream s;
s << filename;
// If this is the first file to load leases from, we should check
// if the file with the .completed prefix exists. If it exists
// we are going to skip loading leases from the files with
// postfixes .2 and .1.
if (i == 2) {
s << ".completed";
lease_file.reset(new LeaseFileType(s.str()));
// If the .completed file exists, reduce the value of i to
// skip loop for the file with postfix .1. We will only
// load leases from the .completed file and the lease
// file without postfix (for i = 0).
if (lease_file->exists()) { if (lease_file->exists()) {
--i; LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
completed_exists = true; MAX_LEASE_ERRORS);
}
} }
// If .completed file doesn't exist, load the files with postfixes lease_file.reset(new LeaseFileType(std::string(filename + ".1")));
// .1 and .2. if (lease_file->exists()) {
if (!completed_exists) { LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
std::ostringstream s2; MAX_LEASE_ERRORS);
s2 << filename;
if (i > 0) {
s2 << "." << i;
} }
lease_file.reset(new LeaseFileType(s2.str()));
} }
// Don't open the file if it doesn't exist and it is not the // Always load leases from the primary lease file. If the lease file
// primary lease file - not ending with .1 or .2 or .completed. // doesn't exist it will be created by the LeaseFileLoader. Note
// Those files are optional and we don't want to create them if // that the false value passed as the last parameter to load
// they don't exist. // function causes the function to leave the file open after
if (i == 0 || lease_file->exists()) { // it is parsed. This file will be used by the backend to record
// If the file doesn't exist it will be created as an empty // future lease updates.
// file (with no leases). The last parameter is set to false lease_file.reset(new LeaseFileType(filename));
// when the primary lease file is parsed. This is to
// indicate that the lease file should remain open after
// parsing. The backend will use this file to append future
// lease updates.
LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage, LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
MAX_LEASE_ERRORS, (i != 0)); MAX_LEASE_ERRORS, false);;
}
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment