When mirroring, write content directly, do not verify

When doing a pull --mirror from an archive-z2 repository into another
archive-z2 repository, currently we gunzip/checksum/gzip each content
object.  The re-gzip process in particular is fairly expensive.

This does assume that the upstream content is trusted and correct.
It'd be nice in the future to do at least a CRC check, if not the full
checksum.  (Could we append CRC data to the end of filez objects?)

We could also choose to only do this optimization if fetching over
TLS.

before: 1626 metadata, 20320 content objects fetched; 299634 KiB transferred in 62 seconds
after : 1626 metadata, 20320 content objects fetched; 299634 KiB transferred in 11 seconds
This commit is contained in:
Colin Walters committed 2015-02-05 21:24:21 -05:00
1 parent 247866a9bc
commit fab1e113db
4 files changed
+115 -69

No files matched your search

+56 -42
View File
@@ -123,12 +123,62 @@ write_file_metadata_to_xattr (int fd,
return TRUE;
}
gboolean
_ostree_repo_commit_loose_final (OstreeRepo *self,
const char *checksum,
OstreeObjectType objtype,
int temp_dfd,
const char *temp_filename,
GCancellable *cancellable,
GError **error)
{
gboolean ret = FALSE;
gs_free gchar *tmp_dest = NULL;
int dest_dfd;
char tmpbuf[_OSTREE_LOOSE_PATH_MAX];
const char *dest;
if (self->in_transaction)
{
_ostree_repo_get_tmpobject_path (self, tmpbuf, checksum, objtype);
tmp_dest = g_strdup (tmpbuf);
dest_dfd = self->tmp_dir_fd;
dest = tmp_dest;
}
else
{
_ostree_loose_path (tmpbuf, checksum, OSTREE_OBJECT_TYPE_FILE, self->mode);
if (!_ostree_repo_ensure_loose_objdir_at (self->objects_dir_fd, tmpbuf,
cancellable, error))
goto out;
dest_dfd = self->objects_dir_fd;
dest = tmpbuf;
}
if (G_UNLIKELY (renameat (temp_dfd, temp_filename,
dest_dfd, dest) == -1))
{
if (errno != EEXIST)
{
gs_set_error_from_errno (error, errno);
g_prefix_error (error, "Storing file '%s': ", temp_filename);
goto out;
}
else
(void) unlinkat (temp_dfd, temp_filename, 0);
}
ret = TRUE;
out:
return ret;
}
static gboolean
commit_loose_object_trusted (OstreeRepo *self,
const char *checksum,
OstreeObjectType objtype,
const char *loose_path,
const char *temp_filename,
gboolean object_is_symlink,
guint32 uid,
@@ -268,43 +318,12 @@ commit_loose_object_trusted (OstreeRepo *self,
}
}
}
if (!_ostree_repo_ensure_loose_objdir_at (self->objects_dir_fd, loose_path,
cancellable, error))
if (!_ostree_repo_commit_loose_final (self, checksum, objtype,
self->tmp_dir_fd, temp_filename,
cancellable, error))
goto out;
{
gs_free gchar *tmp_dest = NULL;
int dir;
const char *dest;
if (self->in_transaction)
{
char tmpbuf[_OSTREE_LOOSE_PATH_MAX];
_ostree_repo_get_tmpobject_path (self, tmpbuf, checksum, objtype);
tmp_dest = g_strdup (tmpbuf);
dir = self->tmp_dir_fd;
dest = tmp_dest;
}
else
{
dir = self->objects_dir_fd;
dest = loose_path;
}
if (G_UNLIKELY (renameat (self->tmp_dir_fd, temp_filename,
dir, dest) == -1))
{
if (errno != EEXIST)
{
gs_set_error_from_errno (error, errno);
g_prefix_error (error, "Storing file '%s': ", temp_filename);
goto out;
}
else
(void) unlinkat (self->tmp_dir_fd, temp_filename, 0);
}
}
ret = TRUE;
out:
return ret;
@@ -515,14 +534,10 @@ _ostree_repo_commit_trusted_content_bare (OstreeRepo *self,
GError **error)
{
gboolean ret = FALSE;
char loose_objpath[_OSTREE_LOOSE_PATH_MAX];
if (state->fd != -1)
{
_ostree_loose_path (loose_objpath, checksum, OSTREE_OBJECT_TYPE_FILE, self->mode);
if (!commit_loose_object_trusted (self, checksum, OSTREE_OBJECT_TYPE_FILE,
loose_objpath,
state->temp_filename,
FALSE, uid, gid, mode,
xattrs, state->fd,
@@ -778,7 +793,6 @@ write_object (OstreeRepo *self,
fd = g_file_descriptor_based_get_fd ((GFileDescriptorBased*)temp_out);
if (!commit_loose_object_trusted (self, actual_checksum, objtype,
loose_objpath,
temp_filename,
object_is_symlink,
uid, gid, mode,