003 File Manager
Current Path:
/usr/local/share/doc/db5/programmer_reference
usr
/
local
/
share
/
doc
/
db5
/
programmer_reference
/
π
..
π
BDB_Prog_Reference.pdf
(1.9 MB)
π
am.html
(13.27 KB)
π
am_close.html
(4.17 KB)
π
am_conf.html
(13.76 KB)
π
am_conf_logrec.html
(7.32 KB)
π
am_conf_select.html
(24.85 KB)
π
am_cursor.html
(36.58 KB)
π
am_delete.html
(2.95 KB)
π
am_foreign.html
(9.84 KB)
π
am_get.html
(4.07 KB)
π
am_misc.html
(6.3 KB)
π
am_misc_bulk.html
(17.31 KB)
π
am_misc_db_sql.html
(4.79 KB)
π
am_misc_dbsizes.html
(4.06 KB)
π
am_misc_diskspace.html
(11.57 KB)
π
am_misc_error.html
(4.83 KB)
π
am_misc_faq.html
(10.34 KB)
π
am_misc_partial.html
(7.81 KB)
π
am_misc_perm.html
(4.19 KB)
π
am_misc_stability.html
(4.82 KB)
π
am_misc_struct.html
(5.06 KB)
π
am_misc_tune.html
(9.91 KB)
π
am_opensub.html
(7.84 KB)
π
am_partition.html
(17.19 KB)
π
am_put.html
(4.68 KB)
π
am_second.html
(14.76 KB)
π
am_stat.html
(3.11 KB)
π
am_sync.html
(3.63 KB)
π
am_truncate.html
(2.54 KB)
π
am_upgrade.html
(4.72 KB)
π
am_verify.html
(4.77 KB)
π
apprec.html
(8.14 KB)
π
apprec_auto.html
(12.16 KB)
π
apprec_config.html
(10 KB)
π
apprec_def.html
(9.13 KB)
π
arch.html
(11.09 KB)
π
arch_apis.html
(10.27 KB)
π
arch_bigpic.gif
(2.53 KB)
π
arch_progmodel.html
(3.1 KB)
π
arch_script.html
(4.39 KB)
π
arch_smallpic.gif
(1.58 KB)
π
arch_utilities.html
(8 KB)
π
bdb_usenix.pdf
(79.81 KB)
π
bt_conf.html
(29.94 KB)
π
cam.html
(11.77 KB)
π
cam_app.html
(16.91 KB)
π
cam_fail.html
(7.77 KB)
π
ch13s02.html
(4.19 KB)
π
csharp.html
(7.48 KB)
π
dumpload.html
(5.42 KB)
π
dumpload_format.html
(6.58 KB)
π
dumpload_text.html
(3.39 KB)
π
embedded.html
(31.62 KB)
π
env.html
(7.43 KB)
π
env_create.html
(10.06 KB)
π
env_db_config.html
(4.21 KB)
π
env_encrypt.html
(10.19 KB)
π
env_error.html
(4.77 KB)
π
env_faq.html
(5.54 KB)
π
env_naming.html
(15.54 KB)
π
env_open.html
(4.95 KB)
π
env_region.html
(8.11 KB)
π
env_remote.html
(5.28 KB)
π
env_security.html
(5.64 KB)
π
env_size.html
(8.11 KB)
π
ext.html
(7.13 KB)
π
ext_perl.html
(3.84 KB)
π
ext_php.html
(5.47 KB)
π
general_am_conf.html
(21.43 KB)
π
gettingStarted.css
(1.13 KB)
π
group_membership.html
(20.37 KB)
π
hash_conf.html
(6.96 KB)
π
hash_usenix.pdf
(256.14 KB)
π
heap_conf.html
(4.14 KB)
π
index.html
(77.48 KB)
π
intro.html
(9.57 KB)
π
intro_dbis.html
(15.02 KB)
π
intro_dbisnot.html
(13.49 KB)
π
intro_distrib.html
(2.92 KB)
π
intro_need.html
(5.06 KB)
π
intro_products.html
(14.3 KB)
π
intro_terrain.html
(19.43 KB)
π
intro_what.html
(4.94 KB)
π
intro_where.html
(3.75 KB)
π
java.html
(7.62 KB)
π
java_compat.html
(2.57 KB)
π
java_faq.html
(7.5 KB)
π
java_program.html
(6.69 KB)
π
libtp_usenix.pdf
(243.14 KB)
π
lock.html
(11.29 KB)
π
lock_am_conv.html
(10.62 KB)
π
lock_cam_conv.html
(4.95 KB)
π
lock_config.html
(4.67 KB)
π
lock_dead.html
(7.25 KB)
π
lock_deaddbg.html
(10.32 KB)
π
lock_max.html
(11.04 KB)
π
lock_nondb.html
(4.94 KB)
π
lock_notxn.html
(4.55 KB)
π
lock_page.html
(5.71 KB)
π
lock_stdmode.html
(5.27 KB)
π
lock_timeout.html
(6.16 KB)
π
lock_twopl.html
(4.48 KB)
π
log.html
(7.08 KB)
π
log_config.html
(5.06 KB)
π
log_limits.html
(4.24 KB)
π
magic.s5.be.txt
(3.54 KB)
π
magic.s5.le.txt
(3.56 KB)
π
magic.txt
(1.98 KB)
π
moreinfo.html
(7.45 KB)
π
mp.html
(8.86 KB)
π
mp_config.html
(6.08 KB)
π
mp_warm.html
(13.45 KB)
π
preface.html
(5.1 KB)
π
program.html
(7.21 KB)
π
program_cache.html
(3.3 KB)
π
program_compatible.html
(3.66 KB)
π
program_copy.html
(7.35 KB)
π
program_environ.html
(3.58 KB)
π
program_errorret.html
(10.38 KB)
π
program_faq.html
(4.58 KB)
π
program_mt.html
(7.54 KB)
π
program_namespace.html
(5.66 KB)
π
program_perfmon.html
(32.07 KB)
π
program_ram.html
(12.58 KB)
π
program_runtime.html
(7.09 KB)
π
program_scope.html
(9.8 KB)
π
refs.html
(11.84 KB)
π
rep.html
(16.57 KB)
π
rep_app.html
(9.75 KB)
π
rep_base_meth.html
(8.59 KB)
π
rep_bulk.html
(4.01 KB)
π
rep_clock_skew.html
(5.38 KB)
π
rep_comm.html
(11.28 KB)
π
rep_elect.html
(13.17 KB)
π
rep_ex.html
(9.64 KB)
π
rep_ex_chan.html
(8.52 KB)
π
rep_ex_comm.html
(7.58 KB)
π
rep_ex_rq.html
(5.52 KB)
π
rep_faq.html
(9.2 KB)
π
rep_filename.html
(7.7 KB)
π
rep_id.html
(4.76 KB)
π
rep_init.html
(5.14 KB)
π
rep_lease.html
(18.32 KB)
π
rep_mastersync.html
(11.24 KB)
π
rep_mgr_ack.html
(8.5 KB)
π
rep_mgr_meth.html
(11.06 KB)
π
rep_mgrmulti.html
(10.28 KB)
π
rep_newsite.html
(5.29 KB)
π
rep_partition.html
(9.21 KB)
π
rep_pri.html
(3.64 KB)
π
rep_replicate.html
(18.8 KB)
π
rep_ryw.html
(9.82 KB)
π
rep_trans.html
(21.58 KB)
π
rep_twosite.html
(6.76 KB)
π
repmgr_channels.html
(13.34 KB)
π
rq_conf.html
(18.29 KB)
π
second.javas
(3.87 KB)
π
sequence.html
(4.43 KB)
π
solaris.txt
(5.62 KB)
π
stl.html
(16.28 KB)
π
stl_complex_rw.html
(19.31 KB)
π
stl_container_specific.html
(9.04 KB)
π
stl_db_advanced_usage.html
(9.68 KB)
π
stl_db_usage.html
(13.27 KB)
π
stl_efficienct_use.html
(11.87 KB)
π
stl_examples.html
(8.24 KB)
π
stl_known_issues.html
(4.54 KB)
π
stl_memory_mgmt.html
(9.22 KB)
π
stl_misc.html
(8.22 KB)
π
stl_mt_usage.html
(9.06 KB)
π
stl_persistence.html
(14.74 KB)
π
stl_primitive_rw.html
(8.18 KB)
π
stl_txn_usage.html
(4.88 KB)
π
stl_usecase.html
(3.67 KB)
π
tcl.html
(7.88 KB)
π
tcl_error.html
(5.2 KB)
π
tcl_faq.html
(4.89 KB)
π
tcl_program.html
(3.78 KB)
π
tcl_using.html
(4.43 KB)
π
transapp.cs
(10.34 KB)
π
transapp.html
(8.55 KB)
π
transapp_admin.html
(4.8 KB)
π
transapp_app.html
(25.08 KB)
π
transapp_archival.html
(15.5 KB)
π
transapp_atomicity.html
(5.46 KB)
π
transapp_checkpoint.html
(6.18 KB)
π
transapp_cursor.html
(6.79 KB)
π
transapp_data_open.html
(7.52 KB)
π
transapp_deadlock.html
(7.35 KB)
π
transapp_env_open.html
(8.39 KB)
π
transapp_fail.html
(6.8 KB)
π
transapp_faq.html
(11.26 KB)
π
transapp_filesys.html
(5.89 KB)
π
transapp_hotfail.html
(10.54 KB)
π
transapp_inc.html
(8.09 KB)
π
transapp_journal.html
(4.72 KB)
π
transapp_logfile.html
(5.3 KB)
π
transapp_nested.html
(5.42 KB)
π
transapp_put.html
(12.47 KB)
π
transapp_read.html
(9.9 KB)
π
transapp_reclimit.html
(12.6 KB)
π
transapp_recovery.html
(8.74 KB)
π
transapp_term.html
(6.02 KB)
π
transapp_throughput.html
(9.06 KB)
π
transapp_tune.html
(13.99 KB)
π
transapp_why.html
(3.94 KB)
π
txn.html
(8.63 KB)
π
txn_config.html
(4.5 KB)
π
txn_limits.html
(5.77 KB)
π
witold.html
(745 B)
π
writetest.cs
(2.26 KB)
π
xa.html
(6.69 KB)
π
xa_build.html
(19.12 KB)
π
xa_faq.html
(7.27 KB)
π
xa_xa_config.html
(8.1 KB)
π
xa_xa_intro.html
(4.46 KB)
π
xa_xa_restrict.html
(6.02 KB)
Editing: am_partition.html
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Partitioning databases</title> <link rel="stylesheet" href="gettingStarted.css" type="text/css" /> <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> <link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" /> <link rel="up" href="am.html" title="ChapterΒ 3.Β Access Method Operations" /> <link rel="prev" href="am_opensub.html" title="Opening multiple databases in a single file" /> <link rel="next" href="am_get.html" title="Retrieving records" /> </head> <body> <div xmlns="" class="navheader"> <div class="libver"> <p>Library Version 11.2.5.3</p> </div> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">Partitioning databases</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="am_opensub.html">Prev</a>Β </td> <th width="60%" align="center">ChapterΒ 3.Β Access Method Operations </th> <td width="20%" align="right">Β <a accesskey="n" href="am_get.html">Next</a></td> </tr> </table> <hr /> </div> <div class="sect1" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h2 class="title" style="clear: both"><a id="am_partition"></a>Partitioning databases</h2> </div> </div> </div> <div class="toc"> <dl> <dt> <span class="sect2"> <a href="am_partition.html#am_partition_keys">Specifying partition keys</a> </span> </dt> <dt> <span class="sect2"> <a href="am_partition.html#am_partition_function">Partitioning callback</a> </span> </dt> <dt> <span class="sect2"> <a href="am_partition.html#partition_file_placement">Placing partition files</a> </span> </dt> </dl> </div> <p> You can improve concurrency on your database reads and writes by splitting access to a single database into multiple databases. This helps to avoid contention for internal database pages, as well as allowing you to spread your databases across multiple disks, which can help to improve disk I/O. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <h3 class="title">Note</h3> <p> Database partitions are not supported by the C# and Java APIs at this time. </p> </div> <p> While you can manually do this by creating and using more than one database for your data, DB is capable of partitioning your database for you. When you use DB's built-in database partitioning feature, your access to your data is performed in exactly the same way as if you were only using one database; all the work of knowing which database to use to access a particular record is handled for you under the hood. </p> <p> Only the BTree and Hash access methods are supported for partitioned databases. </p> <p> You indicate that you want your database to be partitioned by calling <a href="../api_reference/C/dbset_partition.html" class="olink">DB->set_partition()</a> before opening your database the first time. You can indicate the directory in which each partition is contained using the <a href="../api_reference/C/dbset_partition_dirs.html" class="olink">DB->set_partition_dirs()</a> method. </p> <p> Once you have partitioned a database, you cannot change your partitioning scheme. </p> <p> There are two ways to indicate what key/data pairs should go on which partition. The first is by specifying an array of <a href="../api_reference/C/dbt.html" class="olink">DBT</a>s that indicate the minimum key value for a given partition. The second is by providing a callback that returns the number of the partition on which a specified key is placed. </p> <div class="sect2" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h3 class="title"><a id="am_partition_keys"></a>Specifying partition keys</h3> </div> </div> </div> <p> For simple cases, you can partition your database by providing an array of <a href="../api_reference/C/dbt.html" class="olink">DBT</a>s, each element of which provides the minimum key value to be placed on a partition. There must be one fewer elements in this array than you have partitions. The first element of the array indicates the minimum key value for the second partition in your database. Key values that are less than the first key value provided in this array are placed on the first partition (partition 0). </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <h3 class="title">Note</h3> <p> You can use partition keys only if you are using the Btree access method. </p> </div> <p> For example, suppose you had a database of fruit, and you want three partitions for your database. Then you need a <a href="../api_reference/C/dbt.html" class="olink">DBT</a> array of size two. The first element in this array indicates the minimum keys that should be placed on partition 1. The second element in this array indicates the minimum key value placed on partition 2. Keys that compare less than the first <a href="../api_reference/C/dbt.html" class="olink">DBT</a> in the array are placed on partition 0. </p> <p> All comparisons are performed according to the lexicographic comparison used by your platform. </p> <p> For example, suppose you want all fruits whose names begin with: </p> <div class="itemizedlist"> <ul type="disc"> <li> <p> 'a' - 'f' to go on partition 0 </p> </li> <li> <p> 'g' - 'p' to go on partition 1 </p> </li> <li> <p> 'q' - 'z' to go on partition 2. </p> </li> </ul> </div> <p> Then you would accomplish this with the following code fragment: </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <h3 class="title">Note</h3> <p> The <a href="../api_reference/C/dbset_partition.html" class="olink">DB->set_partition()</a> partition callback parameter must be <code class="literal">NULL</code> if you are using an array of <a href="../api_reference/C/dbt.html" class="olink">DBT</a>s to partition your database. </p> </div> <a id="prog_am10"></a> <pre class="programlisting">DB *dbp = NULL; DB_ENV *envp = NULL; DBT partKeys[2]; u_int32_t db_flags; const char *file_name = "mydb.db"; int ret; ... /* Skipping environment open to shorten this example */ /* Initialize the DB handle */ ret = db_create(&dbp, envp, 0); if (ret != 0) { fprintf(stderr, "%s\n", db_strerror(ret)); return (EXIT_FAILURE); } /* Setup the partition keys */ memset(&partKeys[0], 0, sizeof(DBT)); partKeys[0].data = "g"; partKeys[0].size = sizeof("g") - 1; memset(&partKeys[1], 0, sizeof(DBT)); partKeys[1].data = "q"; partKeys[1].size = sizeof("q") - 1; dbp->set_partition(dbp, 3, partKeys, NULL); /* Now open the database */ db_flags = DB_CREATE; /* Allow database creation */ ret = dbp->open(dbp, /* Pointer to the database */ NULL, /* Txn pointer */ file_name, /* File name */ NULL, /* Logical db name */ DB_BTREE, /* Database type (using btree) */ db_flags, /* Open flags */ 0); /* File mode. Using defaults */ if (ret != 0) { dbp->err(dbp, ret, "Database '%s' open failed", file_name); return (EXIT_FAILURE); } </pre> </div> <div class="sect2" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h3 class="title"><a id="am_partition_function"></a>Partitioning callback</h3> </div> </div> </div> <p> In some cases, a simple lexicographical comparison of key data will not sufficiently support a partitioning scheme. For those situations, you should write a partitioning function. This function accepts a pointer to the <a href="../api_reference/C/db.html" class="olink">DB</a> and the <a href="../api_reference/C/dbt.html" class="olink">DBT</a>, and it returns the number of the partition on which the key belongs. </p> <p> Note that <a href="../api_reference/C/db.html" class="olink">DB</a> actually places the key on the partition calculated by: </p> <pre class="programlisting">returned_partition modulo number_of_partitions</pre> <p> Also, remember that if you use a partitioning function when you create your database, then you must use the same partitioning function every time you open that database in the future. </p> <p> The following code fragment illustrates a partition callback: </p> <a id="prog_am11"></a> <pre class="programlisting">u_int32_t db_partition_fn(DB *db, DBT *key) { char *key_data; u_int32_t ret_number; /* Obtain your key data, unpacking it as necessary * Here, we do the very simple thing just for illustrative purposes. */ key_data = (char *)key->data; /* Here you would perform whatever comparison you require to determine * what partition the key belongs on. If you return either 0 or the * number of partitions in the database, the key is placed in the first * database partition. Else, it is placed on: * * returned_number mod number_of_partitions */ ret_number = 0; return ret_number; } </pre> <p> You then cause your partition callback to be used by providing it to the <a href="../api_reference/C/dbset_partition.html" class="olink">DB->set_partition()</a> method, as illustrated by the following code fragment. </p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <h3 class="title">Note</h3> <p> The <a href="../api_reference/C/dbset_partition.html" class="olink">DB->set_partition()</a> <a href="../api_reference/C/dbt.html" class="olink">DBT</a> array parameter must be <code class="literal">NULL</code> if you are using a partition call back to partition your database. </p> </div> <a id="prog_am12"></a> <pre class="programlisting">DB *dbp = NULL; DB_ENV *envp = NULL; u_int32_t db_flags; const char *file_name = "mydb.db"; int ret; ... /* Skipping environment open to shorten this example */ /* Initialize the DB handle */ ret = db_create(&dbp, envp, 0); if (ret != 0) { fprintf(stderr, "%s\n", db_strerror(ret)); return (EXIT_FAILURE); } dbp->set_partition(dbp, 3, NULL, db_partition_fn); /* Now open the database */ db_flags = DB_CREATE; /* Allow database creation */ ret = dbp->open(dbp, /* Pointer to the database */ NULL, /* Txn pointer */ file_name, /* File name */ NULL, /* Logical db name */ DB_BTREE, /* Database type (using btree) */ db_flags, /* Open flags */ 0); /* File mode. Using defaults */ if (ret != 0) { dbp->err(dbp, ret, "Database '%s' open failed", file_name); return (EXIT_FAILURE); } </pre> </div> <div class="sect2" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h3 class="title"><a id="partition_file_placement"></a>Placing partition files</h3> </div> </div> </div> <p> When you partition a database, a database file is created on disk in the same way as if you were not partitioning the database. That is, this file uses the name you provide to the <a href="../api_reference/C/dbopen.html" class="olink">DB->open()</a> <code class="literal">file</code> parameter. </p> <p> However, DB then also creates a series of database files on disk, one for each partition that you want to use. These partition files share the same name as the database file name, but are also number sequentially. So if you create a database named <code class="filename">mydb.db</code>, and you create 3 partitions for it, then you will see the following database files on disk: </p> <pre class="programlisting"> mydb.db __dbp.mydb.db.000 __dbp.mydb.db.001 __dbp.mydb.db.002 </pre> <p> All of the database's contents go into the numbered database files. You can cause these files to be placed in different directories (and, hence, different disk partitions or even disks) by using the <a href="../api_reference/C/dbset_partition_dirs.html" class="olink">DB->set_partition_dirs()</a> method. </p> <p> <a href="../api_reference/C/dbset_partition_dirs.html" class="olink">DB->set_partition_dirs()</a> takes a NULL-terminated array of strings, each one of which should represent an existing filesystem directory. </p> <p> If you are using an environment, the directories specified using <a href="../api_reference/C/dbset_partition_dirs.html" class="olink">DB->set_partition_dirs()</a> must also be included in the environment list specified by <a href="../api_reference/C/envadd_data_dir.html" class="olink">DB_ENV->add_data_dir()</a>. </p> <p> If you are not using an environment, then the the directories specified to <a href="../api_reference/C/dbset_partition_dirs.html" class="olink">DB->set_partition_dirs()</a> can be either complete paths to currently existing directories, or paths relative to the application's current working directory. </p> <p> Ideally, you will provide <a href="../api_reference/C/dbset_partition_dirs.html" class="olink">DB->set_partition_dirs()</a> with an array that is the same size as the number of partitions you are creating for your database. Partition files are then placed according to the order that directories are contained in the array; partition 0 is placed in directory_array[0], partition 1 in directory_array[1], and so forth. However, if you provide an array of directories that is smaller than the number of database partitions, then the directories are used on a round-robin fashion. </p> <p> You must call <a href="../api_reference/C/dbset_partition_dirs.html" class="olink">DB->set_partition_dirs()</a> before you create your database, and before you open your database each time thereafter. The array provided to <a href="../api_reference/C/dbset_partition_dirs.html" class="olink">DB->set_partition_dirs()</a> must not change after the database has been created. </p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="am_opensub.html">Prev</a>Β </td> <td width="20%" align="center"> <a accesskey="u" href="am.html">Up</a> </td> <td width="40%" align="right">Β <a accesskey="n" href="am_get.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">Opening multiple databases in a single fileΒ </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top">Β Retrieving records</td> </tr> </table> </div> </body> </html>
Upload File
Create Folder