db/simple: mount points

A SimpleDatabase instance can now "mount" other Database instances at
certain locations.  This is used to use a new SimpleDatabase instance
for each storage mount (issued with the "mount" protocol command).
Each such instance has its own database file, stored in the directory
that is specified with the "cache_directory" option.
This commit is contained in:
Max Kellermann
2014-02-26 08:39:44 +01:00
parent 2a16fc74fd
commit e9a85aa4e4
19 changed files with 603 additions and 24 deletions

View File

@@ -32,15 +32,27 @@ struct Directory;
struct DatabasePlugin;
class EventLoop;
class DatabaseListener;
class PrefixedLightSong;
class SimpleDatabase : public Database {
AllocatedPath path;
std::string path_utf8;
/**
* The path where cache files for Mount() are located.
*/
AllocatedPath cache_path;
Directory *root;
time_t mtime;
/**
* A buffer for GetSong() when prefixing the #LightSong
* instance from a mounted #Database.
*/
mutable PrefixedLightSong *prefixed_light_song;
/**
* A buffer for GetSong().
*/
@@ -52,6 +64,8 @@ class SimpleDatabase : public Database {
SimpleDatabase();
SimpleDatabase(AllocatedPath &&_path);
public:
static Database *Create(EventLoop &loop, DatabaseListener &listener,
const config_param &param,
@@ -73,6 +87,20 @@ public:
return mtime > 0;
}
/**
* @param db the #Database to be mounted; must be "open"; on
* success, this object gains ownership of the given #Database
*/
gcc_nonnull_all
bool Mount(const char *uri, Database *db, Error &error);
gcc_nonnull_all
bool Mount(const char *local_uri, const char *storage_uri,
Error &error);
gcc_nonnull_all
bool Unmount(const char *uri);
/* virtual methods from class Database */
virtual bool Open(Error &error) override;
virtual void Close() override;
@@ -107,6 +135,8 @@ private:
bool Check(Error &error) const;
bool Load(Error &error);
Database *LockUmountSteal(const char *uri);
};
extern const DatabasePlugin simple_db_plugin;