import.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /*
  42. * structures & constants used for the import code
  43. */
  44. /* Number of lines in the entry above which we switch to
  45. using a tree to check for attribute presence in str2entry().
  46. */
  47. #define STR2ENTRY_ATTRIBUTE_PRESENCE_CHECK_THRESHOLD 100
  48. #define IMPORT_ADD_OP_ATTRS_OK 0
  49. #define IMPORT_ADD_OP_ATTRS_NO_PARENT 1
  50. #define IMPORT_COMPLETE_PASS 1
  51. #define IMPORT_INCOMPLETE_PASS 2
  52. /* Constants for index buffering */
  53. #define IMPORT_MAX_INDEX_BUFFER_SIZE 100
  54. #define IMPORT_MIN_INDEX_BUFFER_SIZE 5
  55. #define IMPORT_INDEX_BUFFER_SIZE_CONSTANT (20*20*20*sizeof(ID))
  56. static const int import_sleep_time = 200; /* in millisecs */
  57. extern char *numsubordinates;
  58. extern char *hassubordinates;
  59. typedef struct _import_worker_info ImportWorkerInfo;
  60. typedef struct _import_index_info IndexInfo;
  61. /* structure which describes an indexing job */
  62. struct _import_index_info
  63. {
  64. char *name;
  65. struct attrinfo *ai;
  66. IndexInfo *next;
  67. };
  68. /* item on the entry FIFO */
  69. typedef struct {
  70. struct backentry *entry;
  71. char *filename; /* or NULL */
  72. int line; /* filename/line are used to report errors */
  73. int bad; /* foreman did not like the entry */
  74. size_t esize; /* entry size */
  75. } FifoItem;
  76. typedef struct {
  77. FifoItem *item;
  78. size_t size; /* Queue size in entries (computed in import_fifo_init). */
  79. size_t bsize; /* Queue limitation in max bytes */
  80. size_t c_bsize; /* Current queue size in bytes */
  81. } Fifo;
  82. /* notes on the import gang:
  83. * 1. producer: reads the file(s), performs str2entry() and assigns IDs.
  84. * job->lead_ID is the last entry in the FIFO it's decoded. as it
  85. * circles the FIFO, it pauses whenever it runs into an entry with a
  86. * non-zero refcount, and waits for the worker threads to finish.
  87. * 2. foreman: reads the FIFO (up to lead_ID), adding operational attrs,
  88. * and creating the entrydn & id2entry indexes. job->ready_ID is the
  89. * last entry in the FIFO it's finished with. (workers can't browse
  90. * the entries it's working on because it's effectively modifying the
  91. * entry.)
  92. * 3. workers (one for each other index): read the FIFO (up to ready_ID),
  93. * creating the index for a particular attribute.
  94. */
  95. /* Structure holding stuff about the whole import job */
  96. #define IMPORT_JOB_PROG_HISTORY_SIZE 3
  97. typedef struct {
  98. ldbm_instance *inst; /* db instance we're importing to */
  99. Slapi_Task *task; /* cn=tasks entry ptr */
  100. int flags; /* (see below) */
  101. char **input_filenames; /* NULL-terminated list of charz pointers */
  102. IndexInfo *index_list; /* A list of indexing jobs to do */
  103. ImportWorkerInfo *worker_list; /* A list of threads to work on the
  104. * indexes */
  105. size_t number_indexers; /* count of the indexer threads (not including
  106. * the primary) */
  107. ID starting_ID; /* Import starts work at this ID */
  108. ID first_ID; /* Import pass starts at this ID */
  109. ID lead_ID; /* Highest ID available in the cache */
  110. ID ready_ID; /* Highest ID the foreman is done with */
  111. ID trailing_ID; /* Lowest ID still available in the cache */
  112. int current_pass; /* un-merged pass number in a multi-pass import */
  113. int total_pass; /* total pass number in a multi-pass import */
  114. int skipped; /* # entries skipped because they were bad */
  115. int not_here_skipped; /* # entries skipped because they belong
  116. * to another backend */
  117. size_t merge_chunk_size; /* Allows us to manually override the magic
  118. * voodoo logic for deciding when to begin
  119. * another pass */
  120. int uuid_gen_type; /* kind of uuid to generate */
  121. char *uuid_namespace; /* namespace for name-generated uuid */
  122. import_subcount_stuff *mothers;
  123. double average_progress_rate;
  124. double recent_progress_rate;
  125. double cache_hit_ratio;
  126. time_t start_time;
  127. ID progress_history[IMPORT_JOB_PROG_HISTORY_SIZE];
  128. time_t progress_times[IMPORT_JOB_PROG_HISTORY_SIZE];
  129. size_t job_index_buffer_size; /* Suggested size of index buffering
  130. * for all indexes */
  131. size_t job_index_buffer_suggestion; /* Suggested size of index buffering
  132. * for one index */
  133. char **include_subtrees; /* list of subtrees to import */
  134. char **exclude_subtrees; /* list of subtrees to NOT import */
  135. Fifo fifo; /* entry fifo for indexing */
  136. char *task_status; /* transient state info for the end-user */
  137. PRLock *wire_lock; /* lock for serializing wire imports */
  138. PRCondVar *wire_cv; /* ... and ordering the startup */
  139. PRThread *main_thread; /* for FRI: import_main() thread id */
  140. int encrypt;
  141. } ImportJob;
  142. #define FLAG_INDEX_ATTRS 0x01 /* should we index the attributes? */
  143. #define FLAG_USE_FILES 0x02 /* import from files */
  144. #define FLAG_PRODUCER_DONE 0x04 /* frontend is done sending entries
  145. * for replica initialization */
  146. #define FLAG_ABORT 0x08 /* import has been aborted */
  147. #define FLAG_ONLINE 0x10 /* bring backend online when done */
  148. #define FLAG_REINDEXING 0x20 /* read from id2entry and do indexing */
  149. /* Structure holding stuff about a worker thread and what it's up to */
  150. struct _import_worker_info {
  151. int work_type; /* What sort of work is this ? */
  152. int command; /* Used to control the thread */
  153. int state; /* Thread indicates its state here */
  154. IndexInfo *index_info; /* info on what we're asked to do */
  155. ID last_ID_processed;
  156. ID previous_ID_counted; /* Used by the monitor to calculate progress
  157. * rate */
  158. double rate; /* Number of IDs processed per second */
  159. ID first_ID; /* Tell the thread to start at this ID */
  160. ImportJob *job;
  161. ImportWorkerInfo *next;
  162. size_t index_buffer_size; /* Size of index buffering for this index */
  163. };
  164. /* Values for work_type */
  165. #define WORKER 1
  166. #define FOREMAN 2
  167. #define PRODUCER 3
  168. /* Values for command */
  169. #define RUN 1
  170. #define PAUSE 2
  171. #define ABORT 3
  172. #define STOP 4
  173. /* Values for state */
  174. #define WAITING 1
  175. #define RUNNING 2
  176. #define FINISHED 3
  177. #define ABORTED 4
  178. /* this is just a convenience, because the slapi_ch_* calls are annoying */
  179. #define CALLOC(name) (name *)slapi_ch_calloc(1, sizeof(name))
  180. #define FREE(x) slapi_ch_free((void **)&(x))
  181. /* import.c */
  182. FifoItem *import_fifo_fetch(ImportJob *job, ID id, int worker, int shift);
  183. void import_free_job(ImportJob *job);
  184. void import_log_notice(ImportJob *job, char *format, ...)
  185. #ifdef __GNUC__
  186. __attribute__ ((format (printf, 2, 3)));
  187. #else
  188. ;
  189. #endif
  190. void import_abort_all(ImportJob *job, int wait_for_them);
  191. int import_entry_belongs_here(Slapi_Entry *e, backend *be);
  192. int import_make_merge_filenames(char *directory, char *indexname, int pass,
  193. char **oldname, char **newname);
  194. void import_main(void *arg);
  195. int import_main_offline(void *arg);
  196. int ldbm_back_ldif2ldbm_deluxe(Slapi_PBlock *pb);
  197. /* import-merge.c */
  198. int import_mega_merge(ImportJob *job);
  199. /* ldif2ldbm.c */
  200. void reset_progress( void );
  201. void report_progress( int count, int done );
  202. int add_op_attrs(Slapi_PBlock *pb, struct ldbminfo *li, struct backentry *ep,
  203. int *status);
  204. /* import-threads.c */
  205. void import_producer(void *param);
  206. void index_producer(void *param);
  207. void import_foreman(void *param);
  208. void import_worker(void *param);