Remove EmptyGenerateFileLocation.

GitOrigin-RevId: 83cacf7526496f5ef3a2cb2ae0df19d384bdf04a
This commit is contained in:
levlam 2018-01-20 17:06:22 +03:00
parent fbb2dc6ccb
commit ef071614b9
4 changed files with 43 additions and 57 deletions

View File

@ -185,7 +185,7 @@ class FileDb : public FileDbInterface {
}
string generate_key;
if (file_data.generate_.type_ == GenerateFileLocation::Type::Full) {
generate_key = as_key(file_data.generate_.full_);
generate_key = as_key(file_data.generate_.full());
}
send_closure(file_db_actor_, &FileDbActor::clear_file_data, id, remote_key, local_key, generate_key);
}
@ -200,7 +200,7 @@ class FileDb : public FileDbInterface {
}
string generate_key;
if (file_data.generate_.type_ == GenerateFileLocation::Type::Full && new_generate) {
generate_key = as_key(file_data.generate_.full_);
generate_key = as_key(file_data.generate_.full());
}
LOG(DEBUG) << "SAVE " << id << " -> " << file_data << " "
<< tag("remote", format::as_hex_dump<4>(Slice(remote_key)))

View File

@ -11,7 +11,7 @@
namespace td {
struct LocalFileLocation;
class LocalFileLocation;
class ResourceManager;
class FileLoaderActor : public NetQueryCallback {

View File

@ -695,8 +695,10 @@ inline StringBuilder &operator<<(StringBuilder &string_builder,
return string_builder << "]";
}
struct RemoteFileLocation {
enum class Type : int32 { Empty, Partial, Full } type_;
class RemoteFileLocation {
public:
enum class Type : int32 { Empty, Partial, Full };
Type type_;
Variant<EmptyRemoteFileLocation, PartialRemoteFileLocation, FullRemoteFileLocation> variant_;
template <class StorerT>
@ -710,18 +712,12 @@ struct RemoteFileLocation {
});
CHECK(ok);
}
EmptyRemoteFileLocation &empty_location() {
return variant_.get<0>();
}
PartialRemoteFileLocation &partial() {
return variant_.get<1>();
}
FullRemoteFileLocation &full() {
return variant_.get<2>();
}
const EmptyRemoteFileLocation &empty_location() const {
return variant_.get<0>();
}
const PartialRemoteFileLocation &partial() const {
return variant_.get<1>();
}
@ -734,7 +730,7 @@ struct RemoteFileLocation {
switch (type_) {
case Type::Empty: {
variant_ = EmptyRemoteFileLocation();
return empty_location().parse(parser);
return;
}
case Type::Partial: {
variant_ = PartialRemoteFileLocation();
@ -792,8 +788,8 @@ inline bool operator!=(const EmptyLocalFileLocation &lhs, const EmptyLocalFileLo
struct PartialLocalFileLocation {
FileType type_;
string path_;
int part_size_;
int ready_part_count_;
int32 part_size_;
int32 ready_part_count_;
string iv_;
template <class StorerT>
@ -880,23 +876,18 @@ inline StringBuilder &operator<<(StringBuilder &sb, const FullLocalFileLocation
return sb << tag("path", location.path_);
}
struct LocalFileLocation {
class LocalFileLocation {
public:
enum class Type : int32 { Empty, Partial, Full };
Type type_;
Variant<EmptyLocalFileLocation, PartialLocalFileLocation, FullLocalFileLocation> variant_;
EmptyLocalFileLocation &empty_location() {
return variant_.get<0>();
}
PartialLocalFileLocation &partial() {
return variant_.get<1>();
}
FullLocalFileLocation &full() {
return variant_.get<2>();
}
const EmptyLocalFileLocation &empty_location() const {
return variant_.get<0>();
}
const PartialLocalFileLocation &partial() const {
return variant_.get<1>();
}
@ -920,7 +911,7 @@ struct LocalFileLocation {
switch (type_) {
case Type::Empty:
variant_ = EmptyLocalFileLocation();
return parse(empty_location(), parser);
return;
case Type::Partial:
variant_ = PartialLocalFileLocation();
return parse(partial(), parser);
@ -950,23 +941,6 @@ inline bool operator!=(const LocalFileLocation &lhs, const LocalFileLocation &rh
return !(lhs == rhs);
}
struct EmptyGenerateFileLocation {
template <class StorerT>
void store(StorerT &storer) const {
}
template <class ParserT>
void parse(ParserT &parser) {
}
};
inline bool operator==(const EmptyGenerateFileLocation &lhs, const EmptyGenerateFileLocation &rhs) {
return true;
}
inline bool operator!=(const EmptyGenerateFileLocation &lhs, const EmptyGenerateFileLocation &rhs) {
return !(lhs == rhs);
}
struct FullGenerateFileLocation {
FileType type_{FileType::None};
string original_path_;
@ -1019,33 +993,41 @@ inline StringBuilder &operator<<(StringBuilder &string_builder,
<< tag("conversion", full_generated_file_location.conversion_) << "]";
}
struct GenerateFileLocation {
class GenerateFileLocation {
public:
enum class Type : int32 { Empty, Full };
Type type_;
EmptyGenerateFileLocation empty_;
FullGenerateFileLocation full_;
FullGenerateFileLocation &full() {
CHECK(type_ == Type::Full);
return full_;
}
const FullGenerateFileLocation &full() const {
CHECK(type_ == Type::Full);
return full_;
}
template <class StorerT>
void store(StorerT &storer) const {
storer.store_int(static_cast<int32>(type_));
td::store(type_, storer);
switch (type_) {
case Type::Empty:
return empty_.store(storer);
return;
case Type::Full:
return full_.store(storer);
return td::store(full_, storer);
}
UNREACHABLE();
}
template <class ParserT>
void parse(ParserT &parser) {
type_ = static_cast<Type>(parser.fetch_int());
td::parse(type_, parser);
switch (type_) {
case Type::Empty:
return empty_.parse(parser);
return;
case Type::Full:
return full_.parse(parser);
return td::parse(full_, parser);
}
return parser.set_error("Invalid type in LocalFileLocation");
return parser.set_error("Invalid type in GenerateFileLocation");
}
GenerateFileLocation() : type_(Type::Empty) {
@ -1053,9 +1035,13 @@ struct GenerateFileLocation {
explicit GenerateFileLocation(const FullGenerateFileLocation &full) : type_(Type::Full), full_(full) {
}
GenerateFileLocation(FileType file_type, string original_path, string conversion)
: type_(Type::Full), full_(file_type, std::move(original_path), std::move(conversion)) {
: type_(Type::Full), full_{file_type, std::move(original_path), std::move(conversion)} {
}
private:
FullGenerateFileLocation full_;
};
inline bool operator==(const GenerateFileLocation &lhs, const GenerateFileLocation &rhs) {
@ -1064,9 +1050,9 @@ inline bool operator==(const GenerateFileLocation &lhs, const GenerateFileLocati
}
switch (lhs.type_) {
case GenerateFileLocation::Type::Empty:
return lhs.empty_ == rhs.empty_;
return true;
case GenerateFileLocation::Type::Full:
return lhs.full_ == rhs.full_;
return lhs.full() == rhs.full();
}
UNREACHABLE();
return false;

View File

@ -184,7 +184,7 @@ bool FileNode::need_pmc_flush() const {
bool has_generate_location = generate_.type_ == GenerateFileLocation::Type::Full;
// Do not save "#file_id#" conversion.
if (has_generate_location && begins_with(generate_.full_.conversion_, "#file_id#")) {
if (has_generate_location && begins_with(generate_.full().conversion_, "#file_id#")) {
has_generate_location = false;
}
@ -229,7 +229,7 @@ bool FileView::has_generate_location() const {
}
const FullGenerateFileLocation &FileView::generate_location() const {
CHECK(has_generate_location());
return node_->generate_.full_;
return node_->generate_.full();
}
int64 FileView::size() const {
@ -1112,7 +1112,7 @@ void FileManager::flush_to_pmc(FileNode *node, bool new_remote, bool new_local,
data.generate_ = node->generate_;
if (data.generate_.type_ == GenerateFileLocation::Type::Full &&
begins_with(data.generate_.full_.conversion_, "#file_id#")) {
begins_with(data.generate_.full().conversion_, "#file_id#")) {
data.generate_ = GenerateFileLocation();
}
@ -1542,7 +1542,7 @@ void FileManager::run_generate(FileNode *node) {
QueryId id = queries_container_.create(Query{file_id, Query::Generate});
node->generate_id_ = id;
send_closure(file_generate_manager_, &FileGenerateManager::generate_file, id, node->generate_.full_, node->local_,
send_closure(file_generate_manager_, &FileGenerateManager::generate_file, id, node->generate_.full(), node->local_,
node->name_, [file_manager = this, id] {
class Callback : public FileGenerateCallback {
ActorId<FileManager> actor_;