Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:add zdbi program
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:98ef403a3ffcb8afc2b09d405f20c618cb3c17c1
User & Date: brandon 2016-06-12 16:23:51
Context
2016-06-12
17:00
remove support for kyotocabinet and add support for mmap-size and cache-size for all executables check-in: c8eb4e153d user: brandon tags: trunk
16:23
add zdbi program check-in: 98ef403a3f user: brandon tags: trunk
16:02
make all program sources more homogeneous check-in: b9cf7437a2 user: brandon tags: trunk
Changes

Changes to ChangeLog.







1
2
3
4
5
6
7






2016-05-27  Brandon Invergo  <brandon@invergo.net>

	* src/zdbc.c (parse_opt): Correct a long-standing bug in setting
	the mmap_size and num_buckets.  Clean up warnings.  Set a more
	sensible default memmap size (128KiB).

2016-05-26  Brandon Invergo  <brandon@invergo.net>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
2016-06-12  Brandon Invergo  <brandon@invergo.net>

	* src/zdb.c (zdb_print_info): Add print info function

	* src/zdbi.c: Add program to print out database info

2016-05-27  Brandon Invergo  <brandon@invergo.net>

	* src/zdbc.c (parse_opt): Correct a long-standing bug in setting
	the mmap_size and num_buckets.  Clean up warnings.  Set a more
	sensible default memmap size (128KiB).

2016-05-26  Brandon Invergo  <brandon@invergo.net>

Changes to src/Makefile.am.

20
21
22
23
24
25
26

27
28
29
30
31
32
33
34

35
36
37

LDADD = $(LIBINTL) $(LIBGDBM) $(LIBKYOTOCABINET)	\
	$(top_srcdir)/lib/libzeptodb.a
zdbc_LDADD = $(LDADD)
zdbf_LDADD = $(LDADD)
zdbr_LDADD = $(LDADD)
zdbs_LDADD = $(LDADD)


AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib -I$(srcdir)
bin_PROGRAMS = zdbc zdbf zdbr zdbs

zdbc_SOURCES = zdbc.c zdb.c zdb.h
zdbf_SOURCES = zdbf.c zdb.c zdb.h
zdbr_SOURCES = zdbr.c zdb.c zdb.h
zdbs_SOURCES = zdbs.c zdb.c zdb.h


check-syntax:
	$(CC) $(CFLAGS) $(LIBS) -I. -I.. -Wall -Wextra -pedantic -std=c99 -fsyntax-only $(CHK_SOURCES)







>


|





>



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

LDADD = $(LIBINTL) $(LIBGDBM) $(LIBKYOTOCABINET)	\
	$(top_srcdir)/lib/libzeptodb.a
zdbc_LDADD = $(LDADD)
zdbf_LDADD = $(LDADD)
zdbr_LDADD = $(LDADD)
zdbs_LDADD = $(LDADD)
zdbi_LDADD = $(LDADD)

AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib -I$(srcdir)
bin_PROGRAMS = zdbc zdbf zdbr zdbs zdbi

zdbc_SOURCES = zdbc.c zdb.c zdb.h
zdbf_SOURCES = zdbf.c zdb.c zdb.h
zdbr_SOURCES = zdbr.c zdb.c zdb.h
zdbs_SOURCES = zdbs.c zdb.c zdb.h
zdbi_SOURCES = zdbi.c zdb.c zdb.h

check-syntax:
	$(CC) $(CFLAGS) $(LIBS) -I. -I.. -Wall -Wextra -pedantic -std=c99 -fsyntax-only $(CHK_SOURCES)

Changes to src/zdb.c.

251
252
253
254
255
256
257






































#else
  GDBM_FILE database = (GDBM_FILE)db;
  if (gdbm_reorganize (database))
    return 1;
  return 0;
#endif
}













































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#else
  GDBM_FILE database = (GDBM_FILE)db;
  if (gdbm_reorganize (database))
    return 1;
  return 0;
#endif
}

void
zdb_print_info (void *db)
{
#ifdef HAVE_KYOTOCABINET
  KCDB *database = (KCDB *)db;
  int64_t num_records;
  char *status;
  num_records = kcdbcount (database);
  status = kcdbstatus (database);
  printf ("Number of records:\t%ld\n", num_records);
  printf ("Internal status:\n%s\n", status);
  free (status);
#else
  GDBM_FILE database = (GDBM_FILE)db;
  size_t cache_size;
  size_t mmap_size_out;
  int mmap;
  gdbm_count_t num_records;
  gdbm_setopt (database, GDBM_GETCACHESIZE, &cache_size, sizeof (size_t));
  gdbm_setopt (database, GDBM_GETMAXMAPSIZE, &mmap_size_out, sizeof (size_t));
  gdbm_setopt (database, GDBM_GETMMAP, &mmap, sizeof (int));
  if (gdbm_count (database, &num_records))
    error (0, errno, "Error counting records");
  printf ("Bucket cache size:\t%zd\n", cache_size);
  if (mmap)
    {
      puts ("Memory-map enabled:\ttrue");
      printf ("Memory-map size:\t%zd\n", mmap_size_out);
    }
  else
    {
      puts ("Memory-map enabled:\tfalse");
    }
  printf ("Number of records:\t%lld\n", num_records);
#endif
  return;
}

Changes to src/zdb.h.

50
51
52
53
54
55
56

57
58
int zdb_close (void *, bool);
int zdb_store (void *, char *, size_t, char *, size_t, bool);
void printrec (char *, char *, char *);
int zdb_fetch (void *, char *, size_t, char *);
int zdb_fetchall (void *, char *);
int zdb_remove (void *, char *, size_t, bool);
int zdb_reorganize (void *);


#endif







>


50
51
52
53
54
55
56
57
58
59
int zdb_close (void *, bool);
int zdb_store (void *, char *, size_t, char *, size_t, bool);
void printrec (char *, char *, char *);
int zdb_fetch (void *, char *, size_t, char *);
int zdb_fetchall (void *, char *);
int zdb_remove (void *, char *, size_t, bool);
int zdb_reorganize (void *);
void zdb_print_info (void *db);

#endif

Added src/zdbi.c.















































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* zdbi.c

   Copyright © 2016 Brandon Invergo <brandon@invergo.net>

   This file is part of zeptodb

   zeptodb is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   zeptodb is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with zeptodb.  If not, see <http://www.gnu.org/licenses/>.
*/

#define _GNU_SOURCE

#include <config.h>
#include <string.h>
#include "error.h"
#include "argp.h"
#include <signal.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
#include "zdb.h"

const char *program_name = "zdbi";
const char *argp_program_version = PACKAGE_STRING;
const char *argp_program_bug_address = PACKAGE_BUGREPORT;
static void *database;
static char doc[] =
  "zdbi -- inspect a DBM database";
static char args_doc[] = "DATABASE";

static struct argp_option options[] = {
  {"no-lock", (int)'l', (const char *)NULL, 0,
   "Do not perform any locking of the database file", 0},
  {"verbose", (int)'v', (const char *)NULL, 0,
   "Print extra information.", 0},
#ifdef HAVE_GDBM
  {"no-mmap", (int)'n', (const char *)NULL, 0,
   "Do not memory-map the database file", 0},
#endif
  {(const char *)NULL, 0, (const char *)NULL, 0, (const char *)NULL, 0}
};

struct arguments
{
  char *args[1];
  bool no_lock;
#ifdef HAVE_GDBM
  bool no_mmap;
#endif
  bool verbose;
};

static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
  struct arguments *arguments = state->input;
  unsigned long int size;
  switch (key)
    {
    case 'l':
      arguments->no_lock = true;
      break;
#ifdef HAVE_GDBM
    case 'n':
      arguments->no_mmap = true;
      break;
#endif
    case 'v':
      arguments->verbose = true;
      break;
    case ARGP_KEY_ARG:
      if (state->arg_num >= 1)
        argp_usage (state);
      arguments->args[state->arg_num] = arg;
      break;
    case ARGP_KEY_END:
      if (state->arg_num == 0)
        argp_usage (state);
      break;
    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}

static struct argp argp = {options, parse_opt, args_doc, doc,
                           (const struct argp_child *)NULL,
                           NULL, (const char *)NULL};

static void
termination_handler (int signum __attribute__ ((unused)))
{
  printf ("Interrupt caught, closing database\n");
  if (database && zdb_close (database, false))
    error (EXIT_FAILURE, errno, "Failed to close database");
  else
    exit (EXIT_SUCCESS);
}

int
main (int argc, char **argv)
{
  struct arguments arguments;
  int mode = ZDB_READER;
  error_t argp_result;

  arguments.no_lock = false;
#ifdef HAVE_GDBM
  arguments.no_mmap = false;
#endif
  arguments.verbose = false;

  argp_result = argp_parse (&argp, argc, argv, 0, 0, &arguments);
  if (argp_result)
    error (EXIT_FAILURE, argp_result, "Failed to parse arguments");

  if (signal (SIGINT, termination_handler) == SIG_IGN)
    signal (SIGINT, SIG_IGN);
  if (signal (SIGHUP, termination_handler) == SIG_IGN)
    signal (SIGHUP, SIG_IGN);
  if (signal (SIGTERM, termination_handler) == SIG_IGN)
    signal (SIGTERM, SIG_IGN);

  if (arguments.no_lock)
    mode ^= ZDB_NOLOCK;
#ifdef HAVE_GDBM
  if (arguments.no_mmap)
    mode ^= ZDB_NOMMAP;
#endif

  /* open the database */
  database = zdb_open (arguments.args[0], mode, arguments.verbose);
  if (!database)
    error (EXIT_FAILURE, errno,
           "Failed to open database %s", arguments.args[0]);
  zdb_print_info (database);
  if (zdb_close (database, arguments.verbose) != 0)
    error (EXIT_FAILURE, errno,
           "Failed to close database %s", arguments.args[0]);
  exit (EXIT_SUCCESS);
}