Rename one method

This commit is contained in:
alesapin 2022-06-08 14:57:10 +02:00
parent 56a57e649f
commit 378f9246ca
5 changed files with 36 additions and 24 deletions

View File

@ -240,7 +240,7 @@ void DiskObjectStorageRemoteMetadataRestoreHelper::restore(const Poco::Util::Abs
void DiskObjectStorageRemoteMetadataRestoreHelper::readRestoreInformation(RestoreInformation & restore_information) /// NOLINT
{
auto metadata_str = disk->metadata_storage->readMetadataFileToString(RESTORE_FILE_NAME);
auto metadata_str = disk->metadata_storage->readFileToString(RESTORE_FILE_NAME);
ReadBufferFromString buffer(metadata_str);
try
@ -438,7 +438,7 @@ void DiskObjectStorage::onFreeze(const String & path)
auto tx = metadata_storage->createTransaction();
WriteBufferFromOwnString revision_file_buf ;
writeIntText(metadata_helper->revision_counter.load(), revision_file_buf);
tx->writeMetadataToFile(path + "revision.txt", revision_file_buf.str());
tx->writeStringToFile(path + "revision.txt", revision_file_buf.str());
tx->commit();
}

View File

@ -27,6 +27,12 @@ using MetadataOperationPtr = std::unique_ptr<IMetadataOperation>;
class IMetadataStorage;
/// Tries to provide some "transactions" interface, which allow
/// to execute (commit) operations simultaneously. We don't provide
/// any snapshot isolation here, so no read operations in transactions
/// interface. This transaction is more like "batch operation" than real "transaction".
///
/// But for better usability we can get MetadataStorage interface and use some read methods.
struct IMetadataTransaction : private boost::noncopyable
{
public:
@ -34,11 +40,10 @@ public:
virtual const IMetadataStorage & getStorageForNonTransactionalReads() const = 0;
/// Create empty file in metadata storage
virtual void createEmptyMetadataFile(const std::string & path) = 0;
/// General purpose methods
/// Write metadata string to file
virtual void writeMetadataToFile(const std::string & path, const std::string & data) = 0;
virtual void writeStringToFile(const std::string & path, const std::string & data) = 0;
virtual void setLastModified(const std::string & path, const Poco::Timestamp & timestamp) = 0;
@ -62,14 +67,23 @@ public:
virtual void replaceFile(const std::string & path_from, const std::string & path_to) = 0;
/// Metadata related methods
/// Create empty file in metadata storage
virtual void createEmptyMetadataFile(const std::string & path) = 0;
/// Create metadata file on paths with content (blob_name, size_in_bytes)
virtual void createMetadataFile(const std::string & path, const std::string & blob_name, uint64_t size_in_bytes) = 0;
/// Add to new blob to metadata file (way to implement appends)
virtual void addBlobToMetadata(const std::string & path, const std::string & blob_name, uint64_t size_in_bytes) = 0;
/// Unlink file and return amount of hardlinks left
virtual void unlinkMetadata(const std::string & path) = 0;
/// Unlink metadata file and do something special if required
/// By default just remove file (unlink file).
virtual void unlinkMetadata(const std::string & path)
{
unlinkFile(path);
}
virtual ~IMetadataTransaction() = default;
};
@ -79,13 +93,12 @@ using MetadataTransactionPtr = std::shared_ptr<IMetadataTransaction>;
/// Metadata storage for remote disks like DiskObjectStorage.
/// Support some subset of Disk operations, allow to read/write only
/// small amounts of data (strings).
/// Tries to provide some "transactions" interface, which allow
/// to execute operations simultaneously.
class IMetadataStorage : private boost::noncopyable
{
public:
virtual MetadataTransactionPtr createTransaction() const = 0;
/// General purpose functions (similar to Disk)
virtual const std::string & getPath() const = 0;
virtual bool exists(const std::string & path) const = 0;
@ -105,8 +118,7 @@ public:
virtual uint32_t getHardlinkCount(const std::string & path) const = 0;
/// Read metadata file to string from path
virtual std::string readMetadataFileToString(const std::string & path) const = 0;
virtual std::string readFileToString(const std::string & path) const = 0;
virtual ~IMetadataStorage() = default;

View File

@ -364,7 +364,7 @@ public:
}
void MetadataStorageFromDiskTransaction::writeMetadataToFile( /// NOLINT
void MetadataStorageFromDiskTransaction::writeStringToFile( /// NOLINT
const std::string & path,
const std::string & data)
{
@ -491,7 +491,7 @@ DirectoryIteratorPtr MetadataStorageFromDisk::iterateDirectory(const std::string
}
std::string MetadataStorageFromDisk::readMetadataFileToString(const std::string & path) const
std::string MetadataStorageFromDisk::readFileToString(const std::string & path) const
{
auto buf = disk->readFile(path);
std::string result;
@ -502,7 +502,7 @@ std::string MetadataStorageFromDisk::readMetadataFileToString(const std::string
void MetadataStorageFromDiskTransaction::createEmptyMetadataFile(const std::string & path)
{
auto metadata = std::make_unique<DiskObjectStorageMetadata>(metadata_storage.disk->getPath(), metadata_storage.root_path_for_remote_metadata, path);
writeMetadataToFile(path, metadata->serializeToString());
writeStringToFile(path, metadata->serializeToString());
}
void MetadataStorageFromDiskTransaction::setLastModified(const std::string & path, const Poco::Timestamp & timestamp)
@ -541,7 +541,7 @@ void MetadataStorageFromDiskTransaction::createHardLink(const std::string & path
metadata->incrementRefCount();
writeMetadataToFile(path_from, metadata->serializeToString());
writeStringToFile(path_from, metadata->serializeToString());
addOperation(std::make_unique<CreateHardlinkOperation>(path_from, path_to, *metadata_storage.disk));
}
@ -565,14 +565,14 @@ void MetadataStorageFromDiskTransaction::setReadOnly(const std::string & path)
{
auto metadata = metadata_storage.readMetadata(path);
metadata->setReadOnly();
writeMetadataToFile(path, metadata->serializeToString());
writeStringToFile(path, metadata->serializeToString());
}
void MetadataStorageFromDiskTransaction::createMetadataFile(const std::string & path, const std::string & blob_name, uint64_t size_in_bytes)
{
DiskObjectStorageMetadataPtr metadata = std::make_unique<DiskObjectStorageMetadata>(metadata_storage.disk->getPath(), metadata_storage.root_path_for_remote_metadata, path);
metadata->addObject(blob_name, size_in_bytes);
writeMetadataToFile(path, metadata->serializeToString());
writeStringToFile(path, metadata->serializeToString());
}
void MetadataStorageFromDiskTransaction::addBlobToMetadata(const std::string & path, const std::string & blob_name, uint64_t size_in_bytes)
@ -588,13 +588,13 @@ void MetadataStorageFromDiskTransaction::addBlobToMetadata(const std::string & p
}
metadata->addObject(blob_name, size_in_bytes);
writeMetadataToFile(path, metadata->serializeToString());
writeStringToFile(path, metadata->serializeToString());
}
DiskObjectStorageMetadataPtr MetadataStorageFromDisk::readMetadataUnlocked(const std::string & path, std::shared_lock<std::shared_mutex> &) const
{
auto metadata = std::make_unique<DiskObjectStorageMetadata>(disk->getPath(), root_path_for_remote_metadata, path);
auto str = readMetadataFileToString(path);
auto str = readFileToString(path);
metadata->deserializeFromString(str);
return metadata;
}
@ -660,7 +660,7 @@ void MetadataStorageFromDiskTransaction::unlinkMetadata(const std::string & path
if (ref_count != 0)
{
metadata->decrementRefCount();
writeMetadataToFile(path, metadata->serializeToString());
writeStringToFile(path, metadata->serializeToString());
}
unlinkFile(path);
}

View File

@ -52,7 +52,7 @@ public:
DirectoryIteratorPtr iterateDirectory(const std::string & path) override;
std::string readMetadataFileToString(const std::string & path) const override;
std::string readFileToString(const std::string & path) const override;
std::unordered_map<String, String> getSerializedMetadata(const std::vector<String> & file_paths) const override;
@ -91,7 +91,7 @@ public:
void commit() override;
void writeMetadataToFile(const std::string & path, const std::string & data) override;
void writeStringToFile(const std::string & path, const std::string & data) override;
void createEmptyMetadataFile(const std::string & path) override;

View File

@ -8165,7 +8165,7 @@ public:
writeString(table_shared_id, buffer);
buffer.write("\n", 1);
tx->writeMetadataToFile(file_path, buffer.str());
tx->writeStringToFile(file_path, buffer.str());
tx->commit();
}
@ -8176,7 +8176,7 @@ public:
if (!metadata_storage->exists(file_path))
return false;
auto metadata_str = metadata_storage->readMetadataFileToString(file_path);
auto metadata_str = metadata_storage->readFileToString(file_path);
ReadBufferFromString buffer(metadata_str);
readIntText(version, buffer);
if (version != 1)