Skip to content

Commit

Permalink
meta2: Put the complete URL in container update event
Browse files Browse the repository at this point in the history
Some tools, like oio-replicator,
need the complete URL to work properly.
  • Loading branch information
AymericDu committed Jun 3, 2022
1 parent 2a0868f commit a078e1a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 35 deletions.
17 changes: 9 additions & 8 deletions meta2v2/meta2_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
OpenIO SDS meta2v2
Copyright (C) 2014 Worldline, as part of Redcurrant
Copyright (C) 2015-2019 OpenIO SAS, as part of OpenIO SDS
Copyright (C) 2021 OVH SAS
Copyright (C) 2021-2022 OVH SAS
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -336,7 +336,7 @@ _is_container_initiated(struct sqlx_sqlite3_s *sq3)

/* workaround for a known bug, when the container has no flag because
* of some failed replication (yet to be determined) but it is used
* because of a (now-fixed) inexistant check on the flag. */
* because of a (now-fixed) inexistent check on the flag. */
if (sqlx_admin_has(sq3, M2V2_ADMIN_OBJ_COUNT)
|| sqlx_admin_has(sq3, M2V2_ADMIN_SIZE)) {
GRID_DEBUG("DB partially initiated: [%s][%.s]",
Expand Down Expand Up @@ -366,9 +366,10 @@ _container_state (struct sqlx_sqlite3_s *sq3)
g_free(v);
}

struct oio_url_s *u = sqlx_admin_get_url (sq3);
struct oio_url_s *url = sqlx_admin_get_url(sq3);
GString *gs = oio_event__create_with_id(
META2_EVENTS_PREFIX ".container.state", u, oio_ext_get_reqid());
META2_EVENTS_PREFIX ".container.state", url, oio_ext_get_reqid());
oio_url_clean(url);
g_string_append_static (gs, ",\"data\":{");
append_str(gs, "bucket", sqlx_admin_get_str(sq3, M2V2_ADMIN_BUCKET_NAME));
append_str(gs, "policy", sqlx_admin_get_str(sq3, M2V2_ADMIN_STORAGE_POLICY));
Expand All @@ -379,7 +380,6 @@ _container_state (struct sqlx_sqlite3_s *sq3)
append_int64(gs, "missing-chunks", m2db_get_missing_chunks(sq3));
g_string_append_static (gs, "}}");

oio_url_clean (u);
return g_string_free(gs, FALSE);
}

Expand Down Expand Up @@ -1880,14 +1880,15 @@ meta2_backend_change_callback(struct sqlx_sqlite3_s *sq3,
}

void
meta2_backend_db_properties_change_callback(struct sqlx_sqlite3_s *sq3 UNUSED,
struct meta2_backend_s *m2b, struct oio_url_s *url,
struct db_properties_s *db_properties)
meta2_backend_db_properties_change_callback(struct sqlx_sqlite3_s *sq3,
struct meta2_backend_s *m2b, struct db_properties_s *db_properties)
{
if (m2b->notifier_container_updated) {
struct oio_url_s *url = sqlx_admin_get_url(sq3);
GString *event = oio_event__create_with_id(
META2_EVENTS_PREFIX ".container.update", url,
oio_ext_get_reqid());
oio_url_clean(url);
g_string_append_static(event, ",\"data\":{");
db_properties_to_json(db_properties, event);
gchar *bucket = sqlx_admin_get_str(sq3, M2V2_ADMIN_BUCKET_NAME);
Expand Down
5 changes: 2 additions & 3 deletions meta2v2/meta2_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
OpenIO SDS meta2v2
Copyright (C) 2014 Worldline, as part of Redcurrant
Copyright (C) 2015-2019 OpenIO SAS, as part of OpenIO SDS
Copyright (C) 2021 OVH SAS
Copyright (C) 2021-2022 OVH SAS
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -67,8 +67,7 @@ void meta2_backend_change_callback(struct sqlx_sqlite3_s *sq3,
struct meta2_backend_s *m2b);

void meta2_backend_db_properties_change_callback(struct sqlx_sqlite3_s *sq3,
struct meta2_backend_s *m2b, struct oio_url_s *url,
struct db_properties_s *db_properties);
struct meta2_backend_s *m2b, struct db_properties_s *db_properties);

/* -------------------------------------------------------------------------- */

Expand Down
14 changes: 3 additions & 11 deletions sqliterepo/replication_dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
OpenIO SDS sqliterepo
Copyright (C) 2014 Worldline, as part of Redcurrant
Copyright (C) 2015-2019 OpenIO SAS, as part of OpenIO SDS
Copyright (C) 2021 OVH SAS
Copyright (C) 2021-2022 OVH SAS
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -2188,11 +2188,7 @@ _handler_PROPDEL(struct gridd_reply_ctx_s *reply,
}

if (!err && db_properties) {
struct oio_url_s *url = metautils_message_extract_url(
reply->request);
sqlx_repository_call_db_properties_change_callback(
sq3, url, db_properties);
oio_url_clean(url);
sqlx_repository_call_db_properties_change_callback(sq3, db_properties);
}

sqlx_repository_unlock_and_close_noerror(sq3);
Expand Down Expand Up @@ -2342,11 +2338,7 @@ _handler_PROPSET(struct gridd_reply_ctx_s *reply,
}

if (!err && db_properties) {
struct oio_url_s *url = metautils_message_extract_url(
reply->request);
sqlx_repository_call_db_properties_change_callback(
sq3, url, db_properties);
oio_url_clean(url);
sqlx_repository_call_db_properties_change_callback(sq3, db_properties);
}

sqlx_repository_unlock_and_close_noerror(sq3);
Expand Down
15 changes: 7 additions & 8 deletions sqliterepo/repository.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
OpenIO SDS sqliterepo
Copyright (C) 2014 Worldline, as part of Redcurrant
Copyright (C) 2015-2020 OpenIO SAS, as part of OpenIO SDS
Copyright (C) 2021 OVH SAS
Copyright (C) 2021-2022 OVH SAS
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -303,7 +303,7 @@ sqlx_repository_init(const gchar *vol, const struct sqlx_repo_config_s *cfg,

if (cfg->flags & SQLX_REPO_NOCACHE) {
/* if there are several connections on the same base, we will use a
shared cache that wil prevent us of too many I/O operations. */
shared cache that will prevent too many I/O operations. */
if (SQLITE_OK != sqlite3_enable_shared_cache(1))
GRID_NOTICE("SQLite3 not in SHAREDCACHE mode");
}
Expand Down Expand Up @@ -564,15 +564,14 @@ sqlx_repository_configure_db_properties_change_callback(

void
sqlx_repository_call_db_properties_change_callback(
struct sqlx_sqlite3_s *sq3, struct oio_url_s *url,
struct db_properties_s *db_properties)
struct sqlx_sqlite3_s *sq3, struct db_properties_s *db_properties)
{
if (!sq3 || !sq3->repo || !sq3->repo->running
|| !sq3->repo->db_properties_change_callback)
return;
return sq3->repo->db_properties_change_callback(sq3,
sq3->repo->db_properties_change_callback_data,
url, db_properties);
db_properties);
}

void
Expand Down Expand Up @@ -1194,7 +1193,7 @@ sqlx_repository_timed_open_and_lock(sqlx_repository_t *repo,
}

if (!err) {
/* XXX(jfs): patching the db handle so it has the lastest election_manager
/* XXX(jfs): patching the db handle so it has the latest election_manager
allows reusing a handle from the cache, and that was initiated during
the _post_config hook (when the election_manager was not associated yet
to the repository. */
Expand All @@ -1204,7 +1203,7 @@ sqlx_repository_timed_open_and_lock(sqlx_repository_t *repo,
// This MIGHT happen if a cache is present (and this is the
// common case for m2v2), because the deletion will happen
// when the base exit the cache.
// In facts this SHOULD NOT happend because a base being deleted
// In facts this SHOULD NOT happen because a base being deleted
// is closed with an instruction to exit the cache immediately.
// TODO FIXME this is maybe a good place for an assert().
if ((*result)->deleted)
Expand Down Expand Up @@ -1431,7 +1430,7 @@ sqlx_repository_use_base(sqlx_repository_t *repo, const struct sqlx_name_s *n,
if (!(err = election_init(repo->election_manager, n, peers,
&status, replicated))) {

/* Interleave a DB creation (out of the lock) if explicitely
/* Interleave a DB creation (out of the lock) if explicitly
* allowed by both the request type AND the application */
if (allow_autocreate && sqliterepo_election_lazy_recover) {
err = _base_lazy_recover(repo, n, status);
Expand Down
8 changes: 3 additions & 5 deletions sqliterepo/sqliterepo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
OpenIO SDS sqliterepo
Copyright (C) 2014 Worldline, as part of Redcurrant
Copyright (C) 2015-2019 OpenIO SAS, as part of OpenIO SDS
Copyright (C) 2021 OVH SAS
Copyright (C) 2021-2022 OVH SAS
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -50,8 +50,7 @@ typedef void (*sqlx_repo_change_hook)(struct sqlx_sqlite3_s *sq3,
gpointer cb_data);

typedef void (*sqlx_repo_db_properties_change_hook)(struct sqlx_sqlite3_s *sq3,
gpointer cb_data, struct oio_url_s *url,
struct db_properties_s *db_properties);
gpointer cb_data, struct db_properties_s *db_properties);

typedef void (*sqlx_file_locator_f) (gpointer locator_data,
const struct sqlx_name_s *n, GString *file_name);
Expand Down Expand Up @@ -225,8 +224,7 @@ void sqlx_repository_configure_db_properties_change_callback(
sqlx_repo_db_properties_change_hook cb, gpointer cb_data);

void sqlx_repository_call_db_properties_change_callback(
struct sqlx_sqlite3_s *sq3, struct oio_url_s *url,
struct db_properties_s *db_properties);
struct sqlx_sqlite3_s *sq3, struct db_properties_s *db_properties);

/* Bases operations -------------------------------------------------------- */

Expand Down

0 comments on commit a078e1a

Please sign in to comment.