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

Optimize the configure options. #269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
318 changes: 255 additions & 63 deletions common/config-mgr.c

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions common/config-mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#define SEAF_CONFIG_MGR_H

typedef struct _SeafCfgManager SeafCfgManager;
typedef struct _SeafCfgManagerPriv SeafCfgManagerPriv;
#include "seafile-session.h"

struct _SeafCfgManager {
GKeyFile *config;
SeafDB *db;
struct _SeafCfgManagerPriv *priv;
};
Copy link
Member

Choose a reason for hiding this comment

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

这个结构体应该只包含一个 SeafCfgMgrPriv 的指针,然后 Priv 这个机构在 .c 文件中定义。一般不要把内部的数据机构暴露在头文件中。


typedef struct _SeafileSession SeafileSession;
Expand Down
30 changes: 25 additions & 5 deletions common/fs-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,12 @@ chunking_worker (gpointer vdata, gpointer user_data)
int fd = -1;
ssize_t n;
int idx;
gint64 fixed_block_size;
int fixed_block_size_mb;
char *group = g_key_file_has_group (seaf->config, "fileserver") ? "fileserver" : "httpserver";

fixed_block_size_mb = seaf_cfg_manager_get_config_int (seaf->cfg_mgr, group, "fixed_block_size");
fixed_block_size = fixed_block_size_mb * ((gint64)1 << 20);

chunk->block_buf = g_new0 (char, chunk->len);
if (!chunk->block_buf) {
Expand Down Expand Up @@ -646,7 +652,7 @@ chunking_worker (gpointer vdata, gpointer user_data)
if (chunk->result < 0)
goto out;

idx = chunk->offset / seaf->http_server->fixed_block_size;
Copy link
Member

Choose a reason for hiding this comment

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

所有类似 seaf->http_server->fixed_block_size 这样的配置变量,都应该从结构体中删除,这样才能保证没有漏改的代码。

idx = chunk->offset / fixed_block_size;
memcpy (data->blk_sha1s + idx * CHECKSUM_LENGTH, chunk->checksum, CHECKSUM_LENGTH);

out:
Expand All @@ -673,8 +679,22 @@ split_file_to_block (const char *repo_id,
int n_pending = 0;
CDCDescriptor *chunk;
int ret = 0;
int fixed_block_size_mb;
int max_indexing_threads;
gint64 fixed_block_size;
char *group = g_key_file_has_group (seaf->config, "fileserver") ? "fileserver" : "httpserver";

fixed_block_size_mb = seaf_cfg_manager_get_config_int (seaf->cfg_mgr,
group,
"fixed_block_size");
fixed_block_size = fixed_block_size_mb * ((gint64)1 << 20);

max_indexing_threads = seaf_cfg_manager_get_config_int (seaf->cfg_mgr,
group,
"max_indexing_threads");

n_blocks = (file_size + fixed_block_size - 1) / fixed_block_size;

n_blocks = (file_size + seaf->http_server->fixed_block_size - 1) / seaf->http_server->fixed_block_size;
block_sha1s = g_new0 (uint8_t, n_blocks * CHECKSUM_LENGTH);
if (!block_sha1s) {
seaf_warning ("Failed to allocate block_sha1s.\n");
Expand All @@ -694,7 +714,7 @@ split_file_to_block (const char *repo_id,
data.finished_tasks = finished_tasks;

tpool = g_thread_pool_new (chunking_worker, &data,
seaf->http_server->max_indexing_threads, FALSE, NULL);
max_indexing_threads, FALSE, NULL);
if (!tpool) {
seaf_warning ("Failed to allocate thread pool\n");
ret = -1;
Expand All @@ -705,7 +725,7 @@ split_file_to_block (const char *repo_id,
guint64 len;
guint64 left = (guint64)file_size;
while (left > 0) {
len = ((left >= seaf->http_server->fixed_block_size) ? seaf->http_server->fixed_block_size : left);
len = ((left >= fixed_block_size) ? fixed_block_size : left);

chunk = g_new0 (CDCDescriptor, 1);
chunk->offset = offset;
Expand All @@ -725,7 +745,7 @@ split_file_to_block (const char *repo_id,
goto out;
}
if (indexed)
*indexed += seaf->http_server->fixed_block_size;
*indexed += fixed_block_size;

if ((--n_pending) <= 0) {
if (indexed)
Expand Down
6 changes: 6 additions & 0 deletions common/rpc-service.c
Original file line number Diff line number Diff line change
Expand Up @@ -4336,6 +4336,12 @@ seafile_get_server_config_boolean (const char *group, const char *key, GError **
return seaf_cfg_manager_get_config_boolean (seaf->cfg_mgr, group, key);
}

GList *
seafile_list_config_options (GError **error)
{
return NULL;
}

GObject *
seafile_get_group_shared_repo_by_path (const char *repo_id,
const char *path,
Expand Down
3 changes: 2 additions & 1 deletion fuse/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ seaf_fuse_SOURCES = seaf-fuse.c \
../common/obj-store.c \
../common/obj-backend-fs.c \
../common/obj-backend-riak.c \
../common/seafile-crypt.c
../common/seafile-crypt.c \
../common/config-mgr.c

seaf_fuse_LDADD = @CCNET_LIBS@ \
@GLIB2_LIBS@ @GOBJECT_LIBS@ @SSL_LIBS@ @LIB_RT@ @LIB_UUID@ \
Expand Down
6 changes: 5 additions & 1 deletion fuse/seafile-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ seafile_session_new(const char *central_config_dir,
goto onerror;
}

session->cfg_mgr = seaf_cfg_manager_new (session);
if (!session->cfg_mgr)
goto onerror;

if (read_excluded_users (session) < 0) {
seaf_warning ("Failed to load excluded users.\n");
goto onerror;
Expand Down Expand Up @@ -111,7 +115,7 @@ read_excluded_users (SeafileSession *session)
int l, i;
char *hash_value;

users = seaf_key_file_get_string (session->config, "fuse", "excluded_users", NULL);
users = seaf_cfg_manager_get_config_string (session->cfg_mgr, "fuse", "excluded_users");
if (!users)
return 0;

Expand Down
2 changes: 2 additions & 0 deletions fuse/seafile-session.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "branch-mgr.h"
#include "commit-mgr.h"
#include "repo-mgr.h"
#include "config-mgr.h"

typedef struct _SeafileSession SeafileSession;

Expand All @@ -27,6 +28,7 @@ struct _SeafileSession {
SeafBranchManager *branch_mgr;
SeafCommitManager *commit_mgr;
SeafRepoManager *repo_mgr;
SeafCfgManager *cfg_mgr;

GHashTable *excluded_users;

Expand Down
3 changes: 3 additions & 0 deletions include/seafile-rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ seafile_set_config_int (const char *key, int value, GError **error);
int
seafile_get_config_int (const char *key, GError **error);

GList*
seafile_list_config_options (GError **error);

int
seafile_set_upload_rate_limit (int limit, GError **error);

Expand Down
4 changes: 4 additions & 0 deletions python/seafile/rpcclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,10 @@ def get_server_config_boolean (group, key):
def set_server_config_boolean (group, key, value):
pass

@searpc_func("objlist", [])
def list_config_options ():
pass

@searpc_func("int", ["string", "int"])
def repo_has_been_shared (repo_id, including_groups):
pass
Expand Down
3 changes: 3 additions & 0 deletions python/seaserv/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,9 @@ def set_server_config_boolean (self, group, key, value):
i_value = 1 if bool(value) else 0
return seafserv_threaded_rpc.set_server_config_boolean (group, key, i_value)

def list_config_options (self):
return seafserv_threaded_rpc.list_config_options()

def del_org_group_repo(self, repo_id, org_id, group_id):
seafserv_threaded_rpc.del_org_group_repo(repo_id, org_id, group_id)

Expand Down
1 change: 0 additions & 1 deletion server/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ noinst_HEADERS = web-accesstoken-mgr.h seafile-session.h \
upload-file.h \
access-file.h \
pack-dir.h \
fileserver-config.h \
http-status-codes.h \
zip-download-mgr.h \
index-blocks-mgr.h
Expand Down
7 changes: 0 additions & 7 deletions server/copy-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ seaf_copy_manager_new (struct _SeafileSession *session)
(GDestroyNotify)copy_task_free);
pthread_mutex_init (&mgr->priv->lock, NULL);

mgr->max_files = g_key_file_get_int64 (session->config,
"web_copy", "max_files", NULL);
mgr->max_size = g_key_file_get_int64 (session->config,
"web_copy", "max_size", NULL);
/* size is given in MB */
mgr->max_size <<= 20;

return mgr;
}

Expand Down
3 changes: 0 additions & 3 deletions server/copy-mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ struct _SeafileCopyTask;
struct _SeafCopyManager {
struct _SeafileSession *session;
struct _SeafCopyManagerPriv *priv;

gint64 max_files;
gint64 max_size;
};
typedef struct _SeafCopyManager SeafCopyManager;
typedef struct _SeafCopyManagerPriv SeafCopyManagerPriv;
Expand Down
14 changes: 7 additions & 7 deletions server/fileserver-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <glib.h>

#include "fileserver-config.h"
#include "seafile-session.h"

const char *OLD_GROUP_NAME = "httpserver";
const char *GROUP_NAME = "fileserver";
Expand All @@ -14,22 +14,22 @@ get_group_name(GKeyFile *config)
}

int
fileserver_config_get_integer(GKeyFile *config, char *key, GError **error)
fileserver_config_get_integer(SeafCfgManager *mgr, GKeyFile *config, char *key)
{
const char *group = get_group_name(config);
return g_key_file_get_integer (config, group, key, error);
return seaf_cfg_manager_get_config_int (mgr, group, key);
}

char *
fileserver_config_get_string(GKeyFile *config, char *key, GError **error)
fileserver_config_get_string(SeafCfgManager *mgr, GKeyFile *config, char *key)
{
const char *group = get_group_name(config);
return g_key_file_get_string (config, group, key, error);
return seaf_cfg_manager_get_config_string (mgr, group, key);
}

gboolean
fileserver_config_get_boolean(GKeyFile *config, char *key, GError **error)
fileserver_config_get_boolean(SeafCfgManager *mgr, GKeyFile *config, char *key)
{
const char *group = get_group_name(config);
return g_key_file_get_boolean (config, group, key, error);
return seaf_cfg_manager_get_config_boolean (mgr, group, key);
}
15 changes: 0 additions & 15 deletions server/fileserver-config.h

This file was deleted.

4 changes: 0 additions & 4 deletions server/gc/repo-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,6 @@ seaf_repo_manager_get_repo_history_limit (SeafRepoManager *mgr,
"history", "keep_days");
}

if (per_repo_days < 0) {
per_repo_days = -1;
}

return per_repo_days;
}

Expand Down
Loading