File: compact.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (75 lines) | stat: -rw-r--r-- 2,172 bytes parent folder | download | duplicates (3)
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
// compact.js

t = db.compacttest;
t.drop();
t.insert({ x: 3 });
t.insert({ x: 3 });
t.insert({ x: 5 });
t.insert({ x: 4, z: 2, k: 'aaa' });
t.insert({ x: 4, z: 2, k: 'aaa' });
t.insert({ x: 4, z: 2, k: 'aaa' });
t.insert({ x: 4, z: 2, k: 'aaa' });
t.insert({ x: 4, z: 2, k: 'aaa' });
t.insert({ x: 4, z: 2, k: 'aaa' });
t.ensureIndex({ x: 1 });

print("1");

var res = db.runCommand({ compact: 'compacttest', dev: true, force: true });
printjson(res);
assert(res.ok);
assert(t.count() == 9);
var v = t.validate(true);
assert(v.ok);
assert(v.extentCount == 1);
assert(v.deletedCount == 1);
assert(t.getIndexes().length == 2);
var ssize = t.stats().storageSize;

print("2");
res = db.runCommand({ compact: 'compacttest', dev: true,paddingBytes:1000, force:true });
assert(res.ok);
assert(t.count() == 9);
var v = t.validate(true);
assert(v.ok);
assert(t.stats().storageSize > ssize, "expected more storage given padding is higher. however it rounds off so if something changed this could be");
//printjson(t.stats());

print("z");

t.insert({ x: 4, z: 2, k: { a: "", b: ""} });
t.insert({ x: 4, z: 2, k: { a: "", b: ""} });
t.insert({ x: 4, z: 2, k: { a: "", b: ""} });
t.insert({ x: 4, z: 2, k: { a: "", b: ""} });
t.insert({ x: 4, z: null, k: { f: "", b: ""} });
t.insert({ x: 4, z: null, k: { c: ""} });
t.insert({ x: 4, z: null, k: { h: ""} });
t.insert({ x: 4, z: null });
t.insert({ x: 4, z: 3});
t.insert({ x: 4, z: 2, k: { a: "", b: ""} });
t.insert({ x: 4, z: null, k: { c: ""} });
t.insert({ x: 4, z: null, k: { c: ""} });
t.insert({ x: 4, z: 3, k: { c: ""} });

t.ensureIndex({ z: 1, k: 1 });
//t.ensureIndex({ z: 1, k: 1 }, { unique: true });
//t.ensureIndex({ z: 1, k: 1 }, { dropDups: true, unique:true });

res = db.runCommand({ compact: 'compacttest', dev: true, paddingFactor: 1.2, force:true });
printjson(res);
assert(res.ok);
assert(t.count() > 13);
var v = t.validate(true);
assert(v.ok);

print("3");

// works on an empty collection?
t.remove({});
assert(db.runCommand({ compact: 'compacttest', dev: true, force:true }).ok);
assert(t.count() == 0);
v = t.validate(true);
assert(v.ok);
assert(v.extentCount == 1);
assert(t.getIndexes().length == 3);