Skip to content

Commit

Permalink
Add new function for directory service and update thrift version
Browse files Browse the repository at this point in the history
  • Loading branch information
Yupeng Tang (FA Talent) committed Jun 9, 2019
1 parent cd69fae commit 9051dca
Show file tree
Hide file tree
Showing 25 changed files with 1,651 additions and 117 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions libjiffy/src/jiffy/directory/block/file_size_tracker.cpp
Expand Up @@ -67,11 +67,14 @@ void file_size_tracker::report_file_sizes(std::ofstream &out,
directory_utils::push_path_element(child_path, node->name());
if (node->is_regular_file()) {
auto file = std::dynamic_pointer_cast<ds_file_node>(node);
std::size_t file_size = 0;
for (const auto &chain: file->data_blocks()) {
file_size += storage_->storage_size(chain.tail());
}
out << epoch << "\t" << child_path << "\t" << file_size << "\t" << (file->num_blocks() * file->chain_length())
//std::size_t file_size = 0;
// TODO fix storage size
//for (const auto &chain: file->data_blocks()) {
//file_size += storage_->storage_size(chain.tail());
//}
//out << epoch << "\t" << child_path << "\t" << file_size << "\t" << (file->num_blocks() * file->chain_length())
// << std::endl;
out << epoch << "\t" << child_path << "\t" << (file->num_blocks() * file->chain_length())
<< std::endl;
} else {
auto dir = std::dynamic_pointer_cast<ds_dir_node>(node);
Expand Down
14 changes: 14 additions & 0 deletions libjiffy/src/jiffy/directory/client/directory_client.cpp
Expand Up @@ -3,6 +3,7 @@

#include "directory_client.h"
#include "../fs/directory_type_conversions.h"
#include "jiffy/utils/logger.h"

using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
Expand All @@ -11,6 +12,8 @@ using namespace ::apache::thrift::transport;
namespace jiffy {
namespace directory {

using namespace utils;

directory_client::directory_client(const std::string &host, int port) {
connect(host, port);
}
Expand Down Expand Up @@ -198,5 +201,16 @@ void directory_client::handle_lease_expiry(const std::string &) {
throw directory_ops_exception("Unsupported operation");
}

void directory_client::update_partition(const std::string &path,
const std::string &old_partition_name,
const std::string &new_partition_name,
const std::string &partition_metadata) {
client_->request_partition_data_update(path, old_partition_name, new_partition_name, partition_metadata);
}

int64_t directory_client::get_capacity(const std::string &path, const std::string &partition_name) {
return client_->get_storage_capacity(path, partition_name);
}

}
}
35 changes: 35 additions & 0 deletions libjiffy/src/jiffy/directory/client/directory_client.h
Expand Up @@ -277,11 +277,46 @@ class directory_client : public directory_interface {
*/

void handle_lease_expiry(const std::string &path) override;

// TODO return status when adding or removing fails

/**
* @brief Add a new replica chain to the path
* @param path File path
* @param partition_name Partition name
* @param partition_metadata Partition metadata
* @return The new replica chain structure
*/
replica_chain add_block(const std::string &path,
const std::string &partition_name,
const std::string &partition_metadata) override;

/**
* @brief Remove a replica chain
* @param path File path
* @param partition_name Partition name to be removed
*/
void remove_block(const std::string &path, const std::string &partition_name) override;

/**
* @brief Update partition name and metadata
* @param path File path
* @param partition_name New partition name
* @param partition_metadata New partition metadata
*/
void update_partition(const std::string &path,
const std::string &old_partition_name,
const std::string &new_partition_name,
const std::string &partition_metadata) override;

/**
* @brief Fetch partition capacity
* @param path File path
* @param partition_name Partition name
* @return Partition capacity
*/
int64_t get_capacity(const std::string &path, const std::string &partition_name) override;

private:
/* Socket */
std::shared_ptr<apache::thrift::transport::TSocket> socket_{};
Expand Down
56 changes: 53 additions & 3 deletions libjiffy/src/jiffy/directory/directory_ops.h
Expand Up @@ -240,14 +240,15 @@ enum storage_mode {

/* Replica chain structure */
struct replica_chain {
/* Chain name */
/* Partition name */
std::string name;
/* Block names */
/* Block identifier */
std::vector<std::string> block_ids;
/* Chain metadata */
/* Partition metadata */
std::string metadata;
/* Storage mode */
storage_mode mode;
typedef std::pair<int32_t, int32_t> slot_range;
/**
* Default Constructor
*/
Expand Down Expand Up @@ -319,6 +320,21 @@ struct replica_chain {
bool operator!=(const replica_chain &other) const {
return !(*this == other);
}

bool operator<(const replica_chain &other) const {
return fetch_slot_range().first < other.fetch_slot_range().first;
}

/**
* @brief Fetch slot range from name
* @return Slot range pair
*/
slot_range fetch_slot_range() const {
std::string delimiter = "_";
int32_t slot_begin = atoi(name.substr(0, name.find(delimiter)).c_str());
int32_t slot_end = atoi(name.substr(name.find(delimiter) + 1, name.length()).c_str());
return std::make_pair(slot_begin, slot_end);
}
};

/* File status class */
Expand Down Expand Up @@ -709,6 +725,21 @@ class data_status {
data_blocks_[i].name = name;
}

/**
* @brief Set new name for partition
* @param old_name Old partition name
* @param new_name New partition name
*/
void set_partition_name(const std::string &old_name, const std::string &new_name) {
for (auto &replica : data_blocks_) {
if (replica.name == old_name) {
replica.name = new_name;
return;
}
}
throw directory_ops_exception("Partition not found: " + old_name);
}

/**
* @brief Fetch data block metadata
* @param i Data block offset
Expand All @@ -732,6 +763,20 @@ class data_status {
data_blocks_[i].metadata = metadata;
}

/**
* @brief Set new metadata for partition
* @param name Partition name
* @param metadata New partition metadata
*/
void set_partition_metadata(const std::string &name, const std::string &metadata) {
for (auto &replica : data_blocks_) {
if (replica.name == name) {
replica.metadata = metadata;
return;
}
}
throw directory_ops_exception("Partition not found: " + name);
}
/**
* @brief Add tag
* @param key Key
Expand Down Expand Up @@ -973,6 +1018,11 @@ class directory_management_ops {
const std::string &partition_name,
const std::string &partition_metadata) = 0;
virtual void remove_block(const std::string &path, const std::string &block_name) = 0;
virtual void update_partition(const std::string &path,
const std::string &old_partition_name,
const std::string &new_partition_name,
const std::string &partition_metadata) = 0;
virtual int64_t get_capacity(const std::string &path, const std::string &partition_name) = 0;
};

class directory_interface : public directory_ops, public directory_management_ops {};
Expand Down
32 changes: 32 additions & 0 deletions libjiffy/src/jiffy/directory/fs/directory_service.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9051dca

Please sign in to comment.