mirror of
https://github.com/apple/foundationdb.git
synced 2025-06-01 18:56:00 +08:00
Address some review comments.
This commit is contained in:
parent
e882eb33fc
commit
9358adcf49
@ -22,8 +22,9 @@
|
||||
#include "fdbclient/MonitorLeader.h"
|
||||
#include "flow/actorcompiler.h" // has to be last include
|
||||
|
||||
// Loads and parses the file at 'path', throwing errors if the file cannot be read or the format is invalid.
|
||||
ClusterConnectionFile::ClusterConnectionFile(std::string const& filename) : IClusterConnectionRecord(false) {
|
||||
// Loads and parses the file at 'filename', throwing errors if the file cannot be read or the format is invalid.
|
||||
ClusterConnectionFile::ClusterConnectionFile(std::string const& filename)
|
||||
: IClusterConnectionRecord(ConnectionStringNeedsPersisted::False) {
|
||||
if (!fileExists(filename)) {
|
||||
throw no_cluster_file_found();
|
||||
}
|
||||
@ -34,7 +35,7 @@ ClusterConnectionFile::ClusterConnectionFile(std::string const& filename) : IClu
|
||||
|
||||
// Creates a cluster file with a given connection string and saves it to the specified file.
|
||||
ClusterConnectionFile::ClusterConnectionFile(std::string const& filename, ClusterConnectionString const& contents)
|
||||
: IClusterConnectionRecord(true) {
|
||||
: IClusterConnectionRecord(ConnectionStringNeedsPersisted::True) {
|
||||
this->filename = filename;
|
||||
cs = contents;
|
||||
}
|
||||
@ -45,7 +46,7 @@ ClusterConnectionString const& ClusterConnectionFile::getConnectionString() cons
|
||||
return cs;
|
||||
}
|
||||
|
||||
// Sets the connections string held by this object. Calling this function does not persist the string to disk.
|
||||
// Sets the connections string held by this object and persists it.
|
||||
Future<Void> ClusterConnectionFile::setConnectionString(ClusterConnectionString const& conn) {
|
||||
ASSERT(filename.size());
|
||||
cs = conn;
|
||||
|
@ -28,8 +28,8 @@
|
||||
// An implementation of IClusterConnectionRecord backed by a file.
|
||||
class ClusterConnectionFile : public IClusterConnectionRecord, ReferenceCounted<ClusterConnectionFile>, NonCopyable {
|
||||
public:
|
||||
// Loads and parses the file at 'path', throwing errors if the file cannot be read or the format is invalid.
|
||||
explicit ClusterConnectionFile(std::string const& path);
|
||||
// Loads and parses the file at 'filename', throwing errors if the file cannot be read or the format is invalid.
|
||||
explicit ClusterConnectionFile(std::string const& filename);
|
||||
|
||||
// Creates a cluster file with a given connection string and saves it to the specified file.
|
||||
explicit ClusterConnectionFile(std::string const& filename, ClusterConnectionString const& contents);
|
||||
@ -38,7 +38,7 @@ public:
|
||||
// been persisted or if the file has been modified externally.
|
||||
ClusterConnectionString const& getConnectionString() const override;
|
||||
|
||||
// Sets the connections string held by this object. Calling this function does not persist the string to disk.
|
||||
// Sets the connections string held by this object and persists it.
|
||||
Future<Void> setConnectionString(ClusterConnectionString const&) override;
|
||||
|
||||
// Get the connection string stored in the file.
|
||||
|
@ -27,7 +27,7 @@
|
||||
ClusterConnectionKey::ClusterConnectionKey(Database db,
|
||||
Key connectionStringKey,
|
||||
ClusterConnectionString const& contents,
|
||||
bool needsToBePersisted)
|
||||
ConnectionStringNeedsPersisted needsToBePersisted)
|
||||
: IClusterConnectionRecord(needsToBePersisted), db(db), cs(contents), connectionStringKey(connectionStringKey) {}
|
||||
|
||||
// Loads and parses the connection string at the specified key, throwing errors if the file cannot be read or the
|
||||
@ -41,8 +41,10 @@ ACTOR Future<Reference<ClusterConnectionKey>> ClusterConnectionKey::loadClusterC
|
||||
if (!v.present()) {
|
||||
throw connection_string_invalid();
|
||||
}
|
||||
return makeReference<ClusterConnectionKey>(
|
||||
db, connectionStringKey, ClusterConnectionString(v.get().toString()), false);
|
||||
return makeReference<ClusterConnectionKey>(db,
|
||||
connectionStringKey,
|
||||
ClusterConnectionString(v.get().toString()),
|
||||
ConnectionStringNeedsPersisted::False);
|
||||
} catch (Error& e) {
|
||||
wait(tr.onError(e));
|
||||
}
|
||||
@ -55,8 +57,7 @@ ClusterConnectionString const& ClusterConnectionKey::getConnectionString() const
|
||||
return cs;
|
||||
}
|
||||
|
||||
// Sets the connections string held by this object. Calling this function does not persist the string to the
|
||||
// database.
|
||||
// Sets the connections string held by this object and persists it.
|
||||
Future<Void> ClusterConnectionKey::setConnectionString(ClusterConnectionString const& connectionString) {
|
||||
cs = connectionString;
|
||||
return success(persist());
|
||||
|
@ -41,7 +41,7 @@ public:
|
||||
ClusterConnectionKey(Database db,
|
||||
Key connectionStringKey,
|
||||
ClusterConnectionString const& contents,
|
||||
bool needsToBePersisted = true);
|
||||
ConnectionStringNeedsPersisted needsToBePersisted = ConnectionStringNeedsPersisted::True);
|
||||
|
||||
// Loads and parses the connection string at the specified key, throwing errors if the file cannot be read or the
|
||||
// format is invalid.
|
||||
@ -51,8 +51,7 @@ public:
|
||||
// hasn't been persisted or if the key has been modified externally.
|
||||
ClusterConnectionString const& getConnectionString() const override;
|
||||
|
||||
// Sets the connections string held by this object. Calling this function does not persist the string to the
|
||||
// database.
|
||||
// Sets the connections string held by this object and persists it.
|
||||
Future<Void> setConnectionString(ClusterConnectionString const&) override;
|
||||
|
||||
// Get the connection string stored in the database.
|
||||
|
@ -31,7 +31,8 @@ class ClusterConnectionMemoryRecord : public IClusterConnectionRecord,
|
||||
public:
|
||||
// Creates a cluster file with a given connection string.
|
||||
explicit ClusterConnectionMemoryRecord(ClusterConnectionString const& cs)
|
||||
: IClusterConnectionRecord(false), id(deterministicRandom()->randomUniqueID()), cs(cs) {}
|
||||
: IClusterConnectionRecord(ConnectionStringNeedsPersisted::False), id(deterministicRandom()->randomUniqueID()),
|
||||
cs(cs) {}
|
||||
|
||||
// Returns the connection string currently held in this object.
|
||||
ClusterConnectionString const& getConnectionString() const override;
|
||||
|
@ -77,6 +77,8 @@ private:
|
||||
Key key, keyDesc;
|
||||
};
|
||||
|
||||
FDB_DECLARE_BOOLEAN_PARAM(ConnectionStringNeedsPersisted);
|
||||
|
||||
// A record that stores the connection string used to connect to a cluster. This record can be updated when a cluster
|
||||
// notifies a connected party that the connection string has changed.
|
||||
//
|
||||
@ -85,7 +87,7 @@ private:
|
||||
// one that is only stored in memory.
|
||||
class IClusterConnectionRecord {
|
||||
public:
|
||||
IClusterConnectionRecord(bool connectionStringNeedsPersisted)
|
||||
IClusterConnectionRecord(ConnectionStringNeedsPersisted connectionStringNeedsPersisted)
|
||||
: connectionStringNeedsPersisted(connectionStringNeedsPersisted) {}
|
||||
virtual ~IClusterConnectionRecord() {}
|
||||
|
||||
@ -93,7 +95,7 @@ public:
|
||||
// been persisted or if the persistent storage for the record has been modified externally.
|
||||
virtual ClusterConnectionString const& getConnectionString() const = 0;
|
||||
|
||||
// Sets the connections string held by this object. Calling this function does not persist the record.
|
||||
// Sets the connections string held by this object and persists it.
|
||||
virtual Future<Void> setConnectionString(ClusterConnectionString const&) = 0;
|
||||
|
||||
// If this record is backed by persistent storage, get the connection string from that storage. Otherwise, return
|
||||
@ -129,14 +131,14 @@ protected:
|
||||
// Writes the connection string to the backing persistent storage, if applicable.
|
||||
virtual Future<bool> persist() = 0;
|
||||
|
||||
// Returns whether the connection record contains a connection string that should be persisted upon connection.
|
||||
// Returns whether the connection record contains a connection string that needs to be persisted upon connection.
|
||||
bool needsToBePersisted() const;
|
||||
|
||||
// Clears the flag needs persisted flag.
|
||||
void setPersisted();
|
||||
|
||||
private:
|
||||
// A flag that indicates whether this connection record should be persisted when it succesfully establishes a
|
||||
// A flag that indicates whether this connection record needs to be persisted when it succesfully establishes a
|
||||
// connection.
|
||||
bool connectionStringNeedsPersisted;
|
||||
};
|
||||
|
@ -50,6 +50,8 @@ std::string trim(std::string const& connectionString) {
|
||||
|
||||
} // namespace
|
||||
|
||||
FDB_DEFINE_BOOLEAN_PARAM(ConnectionStringNeedsPersisted);
|
||||
|
||||
Future<bool> IClusterConnectionRecord::upToDate() {
|
||||
ClusterConnectionString temp;
|
||||
return upToDate(temp);
|
||||
|
Loading…
x
Reference in New Issue
Block a user