Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow appdata being stored in a separate object storage multibucket #26142

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {

private $logger;

protected $type = 'file_storage';
protected $genericObjectStore;
protected $appDataObjectStore;

public function __construct($params) {
if (isset($params['objectstore']) && $params['objectstore'] instanceof IObjectStore) {
$this->objectStore = $params['objectstore'];
Expand All @@ -80,6 +84,14 @@ public function __construct($params) {
$this->mkdir('/');
}

// bootstrap object store for app data
$systemConfig = \OC::$server->getSystemConfig();
$appDataStorageConfig = $systemConfig->getValue('appdata_objectstore_multibucket', null);
if ($appDataStorageConfig && isset($appDataStorageConfig['arguments'])) {
$this->genericObjectStore = $params['objectstore'];
$this->appDataObjectStore = new $appDataStorageConfig['class']($appDataStorageConfig['arguments']);
}

$this->logger = \OC::$server->getLogger();
}

Expand Down Expand Up @@ -206,6 +218,7 @@ public function unlink($path) {
if ($stat['mimetype'] === 'httpd/unix-directory') {
return $this->rmdir($path);
}
$this->verifyStorage($path);
try {
$this->objectStore->deleteObject($this->getURN($stat['fileid']));
} catch (\Exception $ex) {
Expand Down Expand Up @@ -289,7 +302,26 @@ public function filetype($path) {
}
}

/**
* Verify and set the current object store for files and appdata files
*
* @param $path
*/
private function verifyStorage($path) {
if ($this->appDataObjectStore !== null) {
$isAppDataFile = $this->isAppDataFile($path);
if ($isAppDataFile && $this->type !== 'appdata_storage') {
$this->type = 'appdata_storage';
$this->objectStore = $this->appDataObjectStore;
} else if (!$isAppDataFile && $this->type !== 'file_storage') {
$this->type = 'file_storage';
$this->objectStore = $this->genericObjectStore;
}
}
}

public function fopen($path, $mode) {
$this->verifyStorage($path);
$path = $this->normalizePath($path);

if (strrpos($path, '.') !== false) {
Expand Down Expand Up @@ -447,6 +479,7 @@ public function file_put_contents($path, $data) {
}

public function writeStream(string $path, $stream, int $size = null): int {
$this->verifyStorage($path);
$stat = $this->stat($path);
if (empty($stat)) {
// create new file
Expand Down Expand Up @@ -528,6 +561,7 @@ public function writeStream(string $path, $stream, int $size = null): int {
}

public function getObjectStore(): IObjectStore {
$this->verifyStorage($path);
return $this->objectStore;
}

Expand Down Expand Up @@ -591,6 +625,7 @@ private function copyFile(ICacheEntry $sourceEntry, string $to) {
$targetUrn = $this->getURN($targetEntry->getId());

try {
$this->verifyStorage($path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->verifyStorage($path);
$this->verifyStorage($to);

$this->objectStore->copyObject($sourceUrn, $targetUrn);
} catch (\Exception $e) {
$cache->remove($to);
Expand Down