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

CLI, lifecycle: delete exceeding object versions #1363

Merged
merged 9 commits into from
Mar 6, 2018
Merged
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
2 changes: 1 addition & 1 deletion conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{ "type": "bool", "name": "meta2_flag_delete_exceeding_versions",
"key": "meta2.delete_exceeding_versions",
"descr": "When adding alias with versioning, deletes exceeding versions.",
"def": true }
"def": false }
]
},
"rawx": {
Expand Down
49 changes: 45 additions & 4 deletions meta2v2/meta2_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ meta2_backend_flush_container(struct meta2_backend_s *m2, struct oio_url_s *url)
if (!(err = sqlx_transaction_begin(sq3, &repctx))) {
if (!(err = m2db_flush_container(sq3->db)))
err = m2db_purge(sq3, _maxvers(sq3), _retention_delay(sq3),
NULL, NULL);
NULL, NULL, NULL);
err = sqlx_transaction_end(repctx, err);
}
m2b_close(sq3);
Expand All @@ -719,7 +719,7 @@ meta2_backend_flush_container(struct meta2_backend_s *m2, struct oio_url_s *url)

GError *
meta2_backend_purge_container(struct meta2_backend_s *m2, struct oio_url_s *url,
m2_onbean_cb cb, gpointer u0)
gint64 *pmaxvers, m2_onbean_cb cb, gpointer u0)
{
GError *err;
struct sqlx_sqlite3_s *sq3 = NULL;
Expand All @@ -729,7 +729,13 @@ meta2_backend_purge_container(struct meta2_backend_s *m2, struct oio_url_s *url,
if (!err) {
EXTRA_ASSERT(sq3 != NULL);
if (!(err = sqlx_transaction_begin(sq3, &repctx))) {
err = m2db_purge(sq3, _maxvers(sq3), _retention_delay(sq3), cb, u0);
gint64 maxvers;
if (pmaxvers)
maxvers = *pmaxvers;
else
maxvers = _maxvers(sq3);
err = m2db_purge(sq3, maxvers, _retention_delay(sq3), NULL,
cb, u0);
err = sqlx_transaction_end(repctx, err);
}
if (!err)
Expand Down Expand Up @@ -1040,6 +1046,42 @@ meta2_backend_force_alias(struct meta2_backend_s *m2b, struct oio_url_s *url,
return err;
}

GError *
meta2_backend_purge_alias(struct meta2_backend_s *m2, struct oio_url_s *url,
gint64 *pmaxvers, m2_onbean_cb cb, gpointer u0)
{
GError *err;
struct sqlx_sqlite3_s *sq3 = NULL;
struct sqlx_repctx_s *repctx = NULL;

EXTRA_ASSERT(m2 != NULL);
EXTRA_ASSERT(url != NULL);

if (!oio_url_has(url, OIOURL_PATH))
return BADREQ("Missing path");

err = m2b_open(m2, url, M2V2_OPEN_MASTERONLY|M2V2_OPEN_ENABLED, &sq3);
if (!err) {
EXTRA_ASSERT(sq3 != NULL);
if (!(err = _transaction_begin(sq3, url, &repctx))) {
gint64 maxvers;
if (pmaxvers)
maxvers = *pmaxvers;
else
maxvers = _maxvers(sq3);
if (!(err = m2db_purge(sq3, maxvers, _retention_delay(sq3),
oio_url_get(url, OIOURL_PATH), cb, u0)))
m2db_increment_version(sq3);
err = sqlx_transaction_end(repctx, err);
}
if (!err)
m2b_add_modified_container(m2, sq3);
m2b_close(sq3);
}

return err;
}

GError*
meta2_backend_insert_beans(struct meta2_backend_s *m2b,
struct oio_url_s *url, GSList *beans, gboolean force)
Expand Down Expand Up @@ -1711,4 +1753,3 @@ meta2_backend_content_from_contentid (struct meta2_backend_s *m2b,

return err;
}

5 changes: 4 additions & 1 deletion meta2v2/meta2_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ GError* meta2_backend_flush_container(struct meta2_backend_s *m2,
struct oio_url_s *url);

GError* meta2_backend_purge_container(struct meta2_backend_s *m2,
struct oio_url_s *url, m2_onbean_cb cb, gpointer u0);
struct oio_url_s *url, gint64 *pmaxvers, m2_onbean_cb cb, gpointer u0);

/* Find and unreference duplicate content headers. */
GError* meta2_backend_dedup_contents(struct meta2_backend_s *m2b,
Expand Down Expand Up @@ -160,6 +160,9 @@ GError* meta2_backend_force_alias(struct meta2_backend_s *m2b,
m2_onbean_cb cb_deleted, gpointer u0_deleted,
m2_onbean_cb cb_added, gpointer u0_added);

GError * meta2_backend_purge_alias(struct meta2_backend_s *m2,
struct oio_url_s *url, gint64 *pmaxvers, m2_onbean_cb cb, gpointer u0);

/* TODO manage properties */
GError* meta2_backend_link_content (struct meta2_backend_s *m2b,
struct oio_url_s *url, GBytes *content_id);
Expand Down
2 changes: 2 additions & 0 deletions meta2v2/meta2_filters.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ M2V2_DECLARE_FILTER(meta2_filter_extract_header_flags32);
M2V2_DECLARE_FILTER(meta2_filter_extract_header_append);
M2V2_DECLARE_FILTER(meta2_filter_extract_header_string_size);
M2V2_DECLARE_FILTER(meta2_filter_extract_header_optional_overwrite);
M2V2_DECLARE_FILTER(meta2_filter_extract_header_string_maxvers);
M2V2_DECLARE_FILTER(meta2_filter_extract_list_params);
M2V2_DECLARE_FILTER(meta2_filter_extract_admin);

Expand Down Expand Up @@ -105,6 +106,7 @@ M2V2_DECLARE_FILTER(meta2_filter_action_get_content_properties);
M2V2_DECLARE_FILTER(meta2_filter_action_del_content_properties);
M2V2_DECLARE_FILTER(meta2_filter_action_generate_beans);
M2V2_DECLARE_FILTER(meta2_filter_action_touch_content);
M2V2_DECLARE_FILTER(meta2_filter_action_purge_content);

#define META2TOUCH_FLAGS_UPDATECSIZE 0x00000001
#define META2TOUCH_FLAGS_RECALCCSIZE 0x00000002
Expand Down
19 changes: 13 additions & 6 deletions meta2v2/meta2_filters_action_container.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,24 @@ meta2_filter_action_purge_container(struct gridd_filter_ctx_s *ctx,
{
struct meta2_backend_s *m2b = meta2_filter_ctx_get_backend(ctx);
struct oio_url_s *url = meta2_filter_ctx_get_url(ctx);
GSList *beans_list = NULL;
gint64 *pmaxvers = NULL;
GSList *beans_list_list = NULL;

const char *maxvers_str = meta2_filter_ctx_get_param(ctx,
NAME_MSGKEY_MAXVERS);
gint64 maxvers;
if (oio_str_is_number(maxvers_str, &maxvers)) {
pmaxvers = &maxvers;
}

GError *err = meta2_backend_purge_container(
meta2_filter_ctx_get_backend(ctx),
meta2_filter_ctx_get_url(ctx), _bean_list_cb, &beans_list);
GError *err = meta2_backend_purge_container(m2b, url, pmaxvers,
_bean_list_cb, &beans_list_list);

for (GSList *l=beans_list; l; l=l->next) {
for (GSList *l = beans_list_list; l; l = l->next) {
_m2b_notify_beans(m2b, url, l->data, "content.deleted", TRUE);
_bean_cleanl2(l->data);
}
g_slist_free(beans_list);
g_slist_free(beans_list_list);

if (!err)
return FILTER_OK;
Expand Down
33 changes: 33 additions & 0 deletions meta2v2/meta2_filters_action_content.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,3 +608,36 @@ meta2_filter_action_touch_content(struct gridd_filter_ctx_s *ctx,
meta2_filter_ctx_set_error(ctx, err);
return FILTER_KO;
}

int
meta2_filter_action_purge_content(struct gridd_filter_ctx_s *ctx,
struct gridd_reply_ctx_s *reply UNUSED)
{
struct meta2_backend_s *m2b = meta2_filter_ctx_get_backend(ctx);
struct oio_url_s *url = meta2_filter_ctx_get_url(ctx);
gint64 *pmaxvers = NULL;
GSList *beans_list_list = NULL;

const char *maxvers_str = meta2_filter_ctx_get_param(ctx,
NAME_MSGKEY_MAXVERS);
gint64 maxvers;
if (oio_str_is_number(maxvers_str, &maxvers)) {
pmaxvers = &maxvers;
}

// Here we are abusing _bean_list_cb with a list of lists of beans
GError *err = meta2_backend_purge_alias(m2b, url, pmaxvers,
_bean_list_cb, &beans_list_list);

for (GSList *l = beans_list_list; l; l = l->next) {
_m2b_notify_beans(m2b, url, l->data, "content.deleted", TRUE);
_bean_cleanl2(l->data);
}
g_slist_free(beans_list_list);

if (!err)
return FILTER_OK;
GRID_DEBUG("Object purge failed (%d): %s", err->code, err->message);
meta2_filter_ctx_set_error(ctx, err);
return FILTER_KO;
}
12 changes: 11 additions & 1 deletion meta2v2/meta2_filters_extract.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ meta2_filter_extract_header_optional_overwrite(struct gridd_filter_ctx_s *ctx,
return FILTER_OK;
}

int
meta2_filter_extract_header_string_maxvers(struct gridd_filter_ctx_s *ctx,
struct gridd_reply_ctx_s *reply)
{
GError *e = NULL;
gchar buf[64];
TRACE_FILTER();
EXTRACT_OPT(NAME_MSGKEY_MAXVERS);
return FILTER_OK;
}

int
meta2_filter_extract_admin(struct gridd_filter_ctx_s *ctx,
struct gridd_reply_ctx_s *reply)
Expand All @@ -290,4 +301,3 @@ meta2_filter_extract_list_params(struct gridd_filter_ctx_s *ctx,
EXTRACT_OPT(NAME_MSGKEY_MAX_KEYS);
return FILTER_OK;
}

21 changes: 19 additions & 2 deletions meta2v2/meta2_gridd_dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,25 @@ static gridd_filter M2V2_HAS_FILTERS[] =
NULL
};

static gridd_filter M2V2_PURGE_FILTERS[] =
static gridd_filter M2V2_PURGE_CONTENT_FILTERS[] =
{
meta2_filter_extract_header_url,
meta2_filter_extract_header_string_maxvers,
meta2_filter_extract_admin,
meta2_filter_fill_subject,
meta2_filter_check_url_cid,
meta2_filter_check_backend,
meta2_filter_check_ns_name,
meta2_filter_check_ns_is_master,
meta2_filter_action_purge_content,
meta2_filter_reply_success,
NULL
};

static gridd_filter M2V2_PURGE_CONTAINER_FILTERS[] =
{
meta2_filter_extract_header_url,
meta2_filter_extract_header_string_maxvers,
meta2_filter_extract_admin,
meta2_filter_fill_subject,
meta2_filter_check_url_cid,
Expand Down Expand Up @@ -484,7 +500,7 @@ meta2_gridd_get_v2_requests(void)
{NAME_MSGNAME_M2V2_DESTROY, (hook) meta2_dispatch_all, M2V2_DESTROY_FILTERS},
{NAME_MSGNAME_M2V2_HAS, (hook) meta2_dispatch_all, M2V2_HAS_FILTERS},
{NAME_MSGNAME_M2V2_ISEMPTY, (hook) meta2_dispatch_all, M2V2_EMPTY_FILTERS},
{NAME_MSGNAME_M2V2_PURGE, (hook) meta2_dispatch_all, M2V2_PURGE_FILTERS},
{NAME_MSGNAME_M2V2_PURGE_CONTAINER, (hook) meta2_dispatch_all, M2V2_PURGE_CONTAINER_FILTERS},
{NAME_MSGNAME_M2V2_DEDUP, (hook) meta2_dispatch_all, M2V2_DEDUP_FILTERS},
{NAME_MSGNAME_M2V2_FLUSH, (hook) meta2_dispatch_all, M2V2_FLUSH_FILTERS},

Expand All @@ -503,6 +519,7 @@ meta2_gridd_get_v2_requests(void)
{NAME_MSGNAME_M2V2_LCHUNK, (hook) meta2_dispatch_all, M2V2_LCHUNK_FILTERS},
{NAME_MSGNAME_M2V2_LHHASH, (hook) meta2_dispatch_all, M2V2_LHHASH_FILTERS},
{NAME_MSGNAME_M2V2_LHID, (hook) meta2_dispatch_all, M2V2_LHID_FILTERS},
{NAME_MSGNAME_M2V2_PURGE_CONTENT, (hook) meta2_dispatch_all, M2V2_PURGE_CONTENT_FILTERS},

/* content properties (container properties now managed through
* sqlx queries) */
Expand Down
3 changes: 2 additions & 1 deletion meta2v2/meta2_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# define NAME_MSGNAME_M2V2_DESTROY "M2_DESTROY"
# define NAME_MSGNAME_M2V2_HAS "M2_HAS"
# define NAME_MSGNAME_M2V2_FLUSH "M2_FLUSH"
# define NAME_MSGNAME_M2V2_PURGE "M2_PURGE"
# define NAME_MSGNAME_M2V2_PURGE_CONTENT "M2_CPURGE"
# define NAME_MSGNAME_M2V2_PURGE_CONTAINER "M2_BPURGE"
# define NAME_MSGNAME_M2V2_DEDUP "M2_DEDUP"
# define NAME_MSGNAME_M2V2_PUT "M2_PUT"
# define NAME_MSGNAME_M2V2_BEANS "M2_PREP"
Expand Down
Loading