repo: Move the transaction stats to a separate struct
This is much easier for callers to handle, and simplifies the API a lot. https://bugzilla.gnome.org/show_bug.cgi?id=707644
This commit is contained in:
1 parent
5082e1d8e9
commit
ef61724269
7 files changed
+76
-69
No files matched your search
@@ -367,18 +367,18 @@ write_object (OstreeRepo *self,
|
||||
{
|
||||
if (OSTREE_OBJECT_TYPE_IS_META (objtype))
|
||||
{
|
||||
self->txn_metadata_objects_written++;
|
||||
self->txn_stats.metadata_objects_written++;
|
||||
}
|
||||
else
|
||||
{
|
||||
self->txn_content_objects_written++;
|
||||
self->txn_content_bytes_written += file_object_length;
|
||||
self->txn_stats.content_objects_written++;
|
||||
self->txn_stats.content_bytes_written += file_object_length;
|
||||
}
|
||||
}
|
||||
if (OSTREE_OBJECT_TYPE_IS_META (objtype))
|
||||
self->txn_metadata_objects_total++;
|
||||
self->txn_stats.metadata_objects_total++;
|
||||
else
|
||||
self->txn_content_objects_total++;
|
||||
self->txn_stats.content_objects_total++;
|
||||
g_mutex_unlock (&self->txn_stats_lock);
|
||||
|
||||
if (checksum)
|
||||
@@ -562,11 +562,7 @@ ostree_repo_prepare_transaction (OstreeRepo *self,
|
||||
else
|
||||
ret_transaction_resume = FALSE;
|
||||
|
||||
self->txn_metadata_objects_total =
|
||||
self->txn_metadata_objects_written =
|
||||
self->txn_content_objects_total =
|
||||
self->txn_content_objects_written =
|
||||
self->txn_content_bytes_written = 0;
|
||||
memset (&self->txn_stats, 0, sizeof (OstreeRepoTransactionStats));
|
||||
|
||||
self->in_transaction = TRUE;
|
||||
if (ret_transaction_resume)
|
||||
@@ -631,14 +627,10 @@ cleanup_tmpdir (OstreeRepo *self,
|
||||
}
|
||||
|
||||
gboolean
|
||||
ostree_repo_commit_transaction_with_stats (OstreeRepo *self,
|
||||
guint *out_metadata_objects_total,
|
||||
guint *out_metadata_objects_written,
|
||||
guint *out_content_objects_total,
|
||||
guint *out_content_objects_written,
|
||||
guint64 *out_content_bytes_written,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_repo_commit_transaction (OstreeRepo *self,
|
||||
OstreeRepoTransactionStats *out_stats,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
|
||||
@@ -655,26 +647,14 @@ ostree_repo_commit_transaction_with_stats (OstreeRepo *self,
|
||||
if (!ot_gfile_ensure_unlinked (self->transaction_lock_path, cancellable, error))
|
||||
goto out;
|
||||
|
||||
if (out_metadata_objects_total) *out_metadata_objects_total = self->txn_metadata_objects_total;
|
||||
if (out_metadata_objects_written) *out_metadata_objects_written = self->txn_metadata_objects_written;
|
||||
if (out_content_objects_total) *out_content_objects_total = self->txn_content_objects_total;
|
||||
if (out_content_objects_written) *out_content_objects_written = self->txn_content_objects_written;
|
||||
if (out_content_bytes_written) *out_content_bytes_written = self->txn_content_bytes_written;
|
||||
if (out_stats)
|
||||
*out_stats = self->txn_stats;
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
ostree_repo_commit_transaction (OstreeRepo *self,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
return ostree_repo_commit_transaction_with_stats (self, NULL, NULL, NULL, NULL, NULL,
|
||||
cancellable, error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
ostree_repo_abort_transaction (OstreeRepo *self,
|
||||
GCancellable *cancellable,
|
||||
@@ -1622,3 +1602,19 @@ ostree_repo_commit_modifier_unref (OstreeRepoCommitModifier *modifier)
|
||||
G_DEFINE_BOXED_TYPE(OstreeRepoCommitModifier, ostree_repo_commit_modifier,
|
||||
ostree_repo_commit_modifier_ref,
|
||||
ostree_repo_commit_modifier_unref);
|
||||
|
||||
static OstreeRepoTransactionStats *
|
||||
ostree_repo_transaction_stats_copy (OstreeRepoTransactionStats *stats)
|
||||
{
|
||||
return g_memdup (stats, sizeof (OstreeRepoTransactionStats));
|
||||
}
|
||||
|
||||
static void
|
||||
ostree_repo_transaction_stats_free (OstreeRepoTransactionStats *stats)
|
||||
{
|
||||
return g_free (stats);
|
||||
}
|
||||
|
||||
G_DEFINE_BOXED_TYPE(OstreeRepoTransactionStats, ostree_repo_transaction_stats,
|
||||
ostree_repo_transaction_stats_copy,
|
||||
ostree_repo_transaction_stats_free);
|
||||
@@ -40,11 +40,7 @@ struct OstreeRepo {
|
||||
|
||||
GFile *transaction_lock_path;
|
||||
GMutex txn_stats_lock;
|
||||
guint txn_metadata_objects_total;
|
||||
guint txn_metadata_objects_written;
|
||||
guint txn_content_objects_total;
|
||||
guint txn_content_objects_written;
|
||||
guint64 txn_content_bytes_written;
|
||||
OstreeRepoTransactionStats txn_stats;
|
||||
|
||||
GMutex cache_lock;
|
||||
GPtrArray *cached_meta_indexes;
|
||||
|
||||
@@ -1332,7 +1332,7 @@ ostree_repo_pull (OstreeRepo *self,
|
||||
if (!run_mainloop_monitor_fetcher (pull_data))
|
||||
goto out;
|
||||
|
||||
if (!ostree_repo_commit_transaction (pull_data->repo, cancellable, error))
|
||||
if (!ostree_repo_commit_transaction (pull_data->repo, NULL, cancellable, error))
|
||||
goto out;
|
||||
|
||||
g_hash_table_iter_init (&hash_iter, updated_refs);
|
||||
|
||||
+37
-12
@@ -79,24 +79,49 @@ gboolean ostree_repo_write_config (OstreeRepo *self,
|
||||
GKeyFile *new_config,
|
||||
GError **error);
|
||||
|
||||
/**
|
||||
* OstreeRepoTransactionStats:
|
||||
* @metadata_objects_total: The total number of metadata objects
|
||||
* in the repository after this transaction has completed.
|
||||
* @metadata_objects_written: The number of metadata objects that
|
||||
* were written to the repository in this transaction.
|
||||
* @content_objects_total: The total number of content objects
|
||||
* in the repository after this transaction has completed.
|
||||
* @content_objects_written: The number of content objects that
|
||||
* were written to the repository in this transaction.
|
||||
* @content_bytes_total: The amount of data added to the repository,
|
||||
* in bytes, counting only content objects.
|
||||
*
|
||||
* A list of statistics for each transaction that may be
|
||||
* interesting for reporting purposes.
|
||||
*/
|
||||
typedef struct _OstreeRepoTransactionStats OstreeRepoTransactionStats;
|
||||
|
||||
struct _OstreeRepoTransactionStats {
|
||||
guint metadata_objects_total;
|
||||
guint metadata_objects_written;
|
||||
guint content_objects_total;
|
||||
guint content_objects_written;
|
||||
guint64 content_bytes_written;
|
||||
|
||||
guint64 padding1;
|
||||
guint64 padding2;
|
||||
guint64 padding3;
|
||||
guint64 padding4;
|
||||
};
|
||||
|
||||
GType ostree_repo_transaction_stats_get_type (void);
|
||||
|
||||
gboolean ostree_repo_prepare_transaction (OstreeRepo *self,
|
||||
gboolean enable_commit_hardlink_scan,
|
||||
gboolean *out_transaction_resume,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
gboolean ostree_repo_commit_transaction (OstreeRepo *self,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
gboolean ostree_repo_commit_transaction_with_stats (OstreeRepo *self,
|
||||
guint *out_metadata_objects_total,
|
||||
guint *out_metadata_objects_written,
|
||||
guint *out_content_objects_total,
|
||||
guint *out_content_objects_written,
|
||||
guint64 *out_content_bytes_written,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_repo_commit_transaction (OstreeRepo *self,
|
||||
OstreeRepoTransactionStats *out_stats,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
gboolean ostree_repo_abort_transaction (OstreeRepo *self,
|
||||
GCancellable *cancellable,
|
||||
|
||||
Reference in new issue
Block a user