Skip to content

Commit

Permalink
Revert "[rpc] support get deleted by batch"
Browse files Browse the repository at this point in the history
This reverts commit 3455d0d.
  • Loading branch information
killing committed Dec 4, 2015
1 parent de9e9f8 commit 40c90ac
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 173 deletions.
6 changes: 2 additions & 4 deletions common/rpc-service.c
Original file line number Diff line number Diff line change
Expand Up @@ -3784,8 +3784,7 @@ seafile_revert_dir (const char *repo_id,

GList *
seafile_get_deleted (const char *repo_id, int show_days,
const char *path, const char *scan_stat,
int limit, GError **error)
const char *path, GError **error)
{
if (!repo_id) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS,
Expand All @@ -3804,8 +3803,7 @@ seafile_get_deleted (const char *repo_id, int show_days,

GList *ret = seaf_repo_manager_get_deleted_entries (seaf->repo_mgr,
repo_id, show_days,
rpath, scan_stat,
limit, error);
rpath, error);
g_free (rpath);

return ret;
Expand Down
3 changes: 1 addition & 2 deletions include/seafile-rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,7 @@ seafile_revert_dir (const char *repo_id,
*/
GList *
seafile_get_deleted (const char *repo_id, int show_days,
const char *path, const char *scan_stat,
int limit, GError **error);
const char *path, GError **error);

/**
* Generate a new token for (repo_id, email) and return it
Expand Down
1 change: 0 additions & 1 deletion lib/repo.vala
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ public class DeletedEntry : Object {
public int mode { get; set; }
public int delete_time { get; set; }
public int64 file_size { get; set; }
public string scan_stat { get; set; }
}

public class RepoTokenInfo: Object {
Expand Down
1 change: 0 additions & 1 deletion lib/rpc_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
[ "objlist", ["int", "string", "string", "int", "int"] ],
[ "objlist", ["string", "int", "string", "string", "string"] ],
[ "objlist", ["string", "int", "string", "int", "int"] ],
[ "objlist", ["string", "int", "string", "string", "int"] ],
[ "objlist", ["string", "string", "string", "string", "int", "int"] ],
[ "object", [] ],
[ "object", ["int"] ],
Expand Down
4 changes: 2 additions & 2 deletions python/seafile/rpcclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ def seafile_revert_dir(repo_id, commit_id, path, user):
pass
revert_dir = seafile_revert_dir

@searpc_func("objlist", ["string", "int", "string", "string", "int"])
def get_deleted(repo_id, show_days, path, scan_stat, limit):
@searpc_func("objlist", ["string", "int", "string"])
def get_deleted(repo_id, show_days, path):
pass

# share repo to user
Expand Down
4 changes: 2 additions & 2 deletions python/seaserv/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ def revert_file(self, repo_id, commit_id, path, username):
def revert_dir(self, repo_id, commit_id, path, username):
return seafserv_threaded_rpc.revert_dir(repo_id, commit_id, path, username)

def get_deleted(self, repo_id, show_days, path='/', scan_stat=None, limit=100):
return seafserv_threaded_rpc.get_deleted(repo_id, show_days, path, scan_stat, limit)
def get_deleted(self, repo_id, show_days, path='/'):
return seafserv_threaded_rpc.get_deleted(repo_id, show_days, path)

# file lock
def check_file_lock(self, repo_id, path, user):
Expand Down
2 changes: 0 additions & 2 deletions server/repo-mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,6 @@ seaf_repo_manager_get_deleted_entries (SeafRepoManager *mgr,
const char *repo_id,
int show_days,
const char *path,
const char *scan_stat,
int limit,
GError **error);

/*
Expand Down
167 changes: 9 additions & 158 deletions server/repo-op.c
Original file line number Diff line number Diff line change
Expand Up @@ -4918,168 +4918,16 @@ hash_to_list (gpointer key, gpointer value, gpointer user_data)
return TRUE;
}

static gint
compare_commit_by_time (gconstpointer a, gconstpointer b, gpointer unused)
{
const SeafCommit *commit_a = a;
const SeafCommit *commit_b = b;

/* Latest commit comes first in the list. */
return (commit_b->ctime - commit_a->ctime);
}

static int
insert_parent_commit (GList **list, GHashTable *hash,
const char *repo_id, int version,
const char *parent_id)
{
SeafCommit *p;
char *key;

if (g_hash_table_lookup (hash, parent_id) != NULL)
return 0;

p = seaf_commit_manager_get_commit (seaf->commit_mgr,
repo_id, version,
parent_id);
if (!p) {
seaf_warning ("Failed to find commit %s\n", parent_id);
return -1;
}

*list = g_list_insert_sorted_with_data (*list, p,
compare_commit_by_time,
NULL);

key = g_strdup (parent_id);
g_hash_table_replace (hash, key, key);

return 0;
}

static int
scan_commits_for_collect_deleted (CollectDelData *data,
const char *prev_scan_stat,
int limit,
char **next_scan_stat)
{
GList *list = NULL;
SeafCommit *commit;
GHashTable *commit_hash;
SeafRepo *repo = data->repo;
int scan_num = 0;
gboolean ret = TRUE;

/* A hash table for recording id of traversed commits. */
commit_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);

char *key;
if (prev_scan_stat == NULL) {
commit = seaf_commit_manager_get_commit (seaf->commit_mgr, repo->id,
repo->version, repo->head->commit_id);
if (!commit) {
ret = FALSE;
goto out;
}
list = g_list_prepend (list, commit);
key = g_strdup (commit->commit_id);
g_hash_table_replace (commit_hash, key, key);
} else {
commit = seaf_commit_manager_get_commit (seaf->commit_mgr, repo->id,
repo->version, prev_scan_stat);
if (!commit) {
ret = FALSE;
goto out;
}
list = g_list_append (list, commit);
key = g_strdup (commit->commit_id);
g_hash_table_replace (commit_hash, key, key);
}

while (list) {
gboolean stop = FALSE;
commit = list->data;
list = g_list_delete_link (list, list);

if (!collect_deleted (commit, data, &stop)) {
seaf_warning("[comit-mgr] CommitTraverseFunc failed\n");
seaf_commit_unref (commit);
ret = FALSE;
goto out;
}

if (stop) {
seaf_commit_unref (commit);
/* stop traverse down from this commit,
* but not stop traversing the tree
*/
continue;
}

if (commit->parent_id) {
if (insert_parent_commit (&list, commit_hash, repo->id,
repo->version,
commit->parent_id) < 0) {
seaf_warning("[comit-mgr] insert parent commit failed\n");
seaf_commit_unref (commit);
ret = FALSE;
goto out;
}
}
if (commit->second_parent_id) {
if (insert_parent_commit (&list, commit_hash, repo->id,
repo->version,
commit->second_parent_id) < 0) {
seaf_warning("[comit-mgr]insert second parent commit failed\n");
seaf_commit_unref (commit);
ret = FALSE;
goto out;
}
}
seaf_commit_unref (commit);

if (++scan_num == limit && (!list || !list->next)) {
break;
}
}

// two scenarios:
// 1. list is empty, indicate scan end
// 2. list only have one commit, as start for next scan
if (list) {
commit = list->data;
*next_scan_stat = g_strdup (commit->commit_id);
seaf_commit_unref (commit);
list = g_list_delete_link (list, list);
}
g_hash_table_destroy (commit_hash);

return ret;

out:
g_hash_table_destroy (commit_hash);
while (list) {
commit = list->data;
seaf_commit_unref (commit);
list = g_list_delete_link (list, list);
}

return ret;
}

GList *
seaf_repo_manager_get_deleted_entries (SeafRepoManager *mgr,
const char *repo_id,
int show_days,
const char *path,
const char *scan_stat,
int limit,
GError **error)
{
SeafRepo *repo;
gint64 truncate_time, show_time;
GList *ret = NULL;
char *next_scan_stat = NULL;

truncate_time = seaf_repo_manager_get_repo_truncate_time (mgr, repo_id);
if (truncate_time == 0)
Expand Down Expand Up @@ -5113,7 +4961,13 @@ seaf_repo_manager_get_deleted_entries (SeafRepoManager *mgr,
data.path = g_strdup ("/");
}

if (!scan_commits_for_collect_deleted (&data, scan_stat, limit, &next_scan_stat)) {
if (!seaf_commit_manager_traverse_commit_tree (seaf->commit_mgr,
repo->id, repo->version,
repo->head->commit_id,
collect_deleted,
&data,
TRUE))
{
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_INTERNAL,
"Internal error");
g_hash_table_destroy (entries);
Expand All @@ -5131,11 +4985,6 @@ seaf_repo_manager_get_deleted_entries (SeafRepoManager *mgr,
g_hash_table_foreach_steal (entries, hash_to_list, &ret);
}

// Append scan_stat entry to the end to indicate the end of scan result
ret = g_list_append (ret, g_object_new (SEAFILE_TYPE_DELETED_ENTRY,
"scan_stat", next_scan_stat,
NULL));

g_hash_table_destroy (entries);

seaf_repo_unref (repo);
Expand All @@ -5144,6 +4993,8 @@ seaf_repo_manager_get_deleted_entries (SeafRepoManager *mgr,
return ret;
}



static SeafCommit *
get_commit(SeafRepo *repo, const char *branch_or_commit)
{
Expand Down
2 changes: 1 addition & 1 deletion server/seaf-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ static void start_rpc_service (CcnetClient *client, int cloud_mode)
searpc_server_register_function ("seafserv-threaded-rpcserver",
seafile_get_deleted,
"get_deleted",
searpc_signature_objlist__string_int_string_string_int());
searpc_signature_objlist__string_int_string());

/* share repo to user */
searpc_server_register_function ("seafserv-threaded-rpcserver",
Expand Down

0 comments on commit 40c90ac

Please sign in to comment.