summaryrefslogtreecommitdiff
path: root/src/utilities/util_compact.c
blob: c6f36c8f4e0a6c885ba82c38973c12c30f9fdfa6 (plain)
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
/*-
 * Copyright (c) 2008-2014 WiredTiger, Inc.
 *	All rights reserved.
 *
 * See the file LICENSE for redistribution information.
 */

#include "util.h"

static int usage(void);

int
util_compact(WT_SESSION *session, int argc, char *argv[])
{
	WT_DECL_RET;
	int ch;
	char *uri;

	uri = NULL;
	while ((ch = util_getopt(argc, argv, "")) != EOF)
		switch (ch) {
		case '?':
		default:
			return (usage());
		}
	argc -= util_optind;
	argv += util_optind;

	/* The remaining argument is the table name. */
	if (argc != 1)
		return (usage());
	if ((uri = util_name(*argv, "table",
	    UTIL_COLGROUP_OK | UTIL_FILE_OK | UTIL_INDEX_OK |
	    UTIL_LSM_OK | UTIL_TABLE_OK)) == NULL)
		return (1);

	if ((ret = session->compact(session, uri, NULL)) != 0) {
		fprintf(stderr, "%s: compact(%s): %s\n",
		    progname, uri, wiredtiger_strerror(ret));
		goto err;
	}

	if (0) {
err:		ret = 1;
	}

	if (uri != NULL)
		free(uri);

	return (ret);
}

static int
usage(void)
{
	(void)fprintf(stderr,
	    "usage: %s %s "
	    "compact uri\n",
	    progname, usage_prefix);
	return (1);
}