1 /* copies-table.c : operations on the `copies' table
3 * ====================================================================
4 * Copyright (c) 2000-2004 CollabNet. All rights reserved.
6 * This software is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at http://subversion.tigris.org/license-1.html.
9 * If newer versions of this license are posted there, you may use a
10 * newer version instead, at your option.
12 * This software consists of voluntary contributions made by many
13 * individuals. For exact contribution history, see the revision
14 * history and logs, available at http://subversion.tigris.org/.
15 * ====================================================================
20 #include "bdb_compat.h"
23 #include "../key-gen.h"
25 #include "../util/skel.h"
26 #include "../util/fs_skels.h"
28 #include "../../libsvn_fs/fs-loader.h"
30 #include "copies-table.h"
31 #include "rev-table.h"
33 #include "svn_private_config.h"
37 svn_fs_bdb__open_copies_table(DB
**copies_p
,
41 const u_int32_t open_flags
= (create
? (DB_CREATE
| DB_EXCL
) : 0);
44 BDB_ERR(svn_fs_bdb__check_version());
45 BDB_ERR(db_create(&copies
, env
, 0));
46 BDB_ERR((copies
->open
)(SVN_BDB_OPEN_PARAMS(copies
, NULL
),
47 "copies", 0, DB_BTREE
,
50 /* Create the initial `next-key' table entry. */
54 BDB_ERR(copies
->put(copies
, 0,
55 svn_fs_base__str_to_dbt(&key
, NEXT_KEY_KEY
),
56 svn_fs_base__str_to_dbt(&value
, "0"), 0));
64 /* Store COPY as a copy named COPY_ID in FS as part of TRAIL. */
65 /* ### only has one caller; might not need to be abstracted */
67 put_copy(svn_fs_t
*fs
,
73 base_fs_data_t
*bfd
= fs
->fsap_data
;
77 /* Convert native type to skel. */
78 SVN_ERR(svn_fs_base__unparse_copy_skel(©_skel
, copy
, pool
));
80 /* Only in the context of this function do we know that the DB call
81 will not attempt to modify COPY_ID, so the cast belongs here. */
82 svn_fs_base__str_to_dbt(&key
, copy_id
);
83 svn_fs_base__skel_to_dbt(&value
, copy_skel
, pool
);
84 svn_fs_base__trail_debug(trail
, "copies", "put");
85 SVN_ERR(BDB_WRAP(fs
, _("storing copy record"),
86 bfd
->copies
->put(bfd
->copies
, trail
->db_txn
,
94 svn_fs_bdb__reserve_copy_id(const char **id_p
,
99 base_fs_data_t
*bfd
= fs
->fsap_data
;
102 char next_key
[MAX_KEY_SIZE
];
105 svn_fs_base__str_to_dbt(&query
, NEXT_KEY_KEY
);
107 /* Get the current value associated with the `next-key' key in the
109 svn_fs_base__trail_debug(trail
, "copies", "get");
110 SVN_ERR(BDB_WRAP(fs
, _("allocating new copy ID (getting 'next-key')"),
111 bfd
->copies
->get(bfd
->copies
, trail
->db_txn
, &query
,
112 svn_fs_base__result_dbt(&result
),
114 svn_fs_base__track_dbt(&result
, pool
);
116 /* Set our return value. */
117 *id_p
= apr_pstrmemdup(pool
, result
.data
, result
.size
);
119 /* Bump to future key. */
121 svn_fs_base__next_key(result
.data
, &len
, next_key
);
122 svn_fs_base__trail_debug(trail
, "copies", "put");
123 db_err
= bfd
->copies
->put(bfd
->copies
, trail
->db_txn
,
124 svn_fs_base__str_to_dbt(&query
, NEXT_KEY_KEY
),
125 svn_fs_base__str_to_dbt(&result
, next_key
),
128 SVN_ERR(BDB_WRAP(fs
, _("bumping next copy key"), db_err
));
134 svn_fs_bdb__create_copy(svn_fs_t
*fs
,
136 const char *src_path
,
137 const char *src_txn_id
,
138 const svn_fs_id_t
*dst_noderev_id
,
145 copy
.src_path
= src_path
;
146 copy
.src_txn_id
= src_txn_id
;
147 copy
.dst_noderev_id
= dst_noderev_id
;
148 return put_copy(fs
, ©
, copy_id
, trail
, pool
);
153 svn_fs_bdb__delete_copy(svn_fs_t
*fs
,
158 base_fs_data_t
*bfd
= fs
->fsap_data
;
162 svn_fs_base__str_to_dbt(&key
, copy_id
);
163 svn_fs_base__trail_debug(trail
, "copies", "del");
164 db_err
= bfd
->copies
->del(bfd
->copies
, trail
->db_txn
, &key
, 0);
165 if (db_err
== DB_NOTFOUND
)
166 return svn_fs_base__err_no_such_copy(fs
, copy_id
);
167 return BDB_WRAP(fs
, _("deleting entry from 'copies' table"), db_err
);
172 svn_fs_bdb__get_copy(copy_t
**copy_p
,
178 base_fs_data_t
*bfd
= fs
->fsap_data
;
184 /* Only in the context of this function do we know that the DB call
185 will not attempt to modify copy_id, so the cast belongs here. */
186 svn_fs_base__trail_debug(trail
, "copies", "get");
187 db_err
= bfd
->copies
->get(bfd
->copies
, trail
->db_txn
,
188 svn_fs_base__str_to_dbt(&key
, copy_id
),
189 svn_fs_base__result_dbt(&value
),
191 svn_fs_base__track_dbt(&value
, pool
);
193 if (db_err
== DB_NOTFOUND
)
194 return svn_fs_base__err_no_such_copy(fs
, copy_id
);
195 SVN_ERR(BDB_WRAP(fs
, _("reading copy"), db_err
));
197 /* Unparse COPY skel */
198 skel
= svn_fs_base__parse_skel(value
.data
, value
.size
, pool
);
200 return svn_fs_base__err_corrupt_copy(fs
, copy_id
);
202 /* Convert skel to native type. */
203 SVN_ERR(svn_fs_base__parse_copy_skel(©
, skel
, pool
));