Skip to content

Instantly share code, notes, and snippets.

@renctan
renctan / bson_comp.js
Created October 4, 2013 17:58
Test for bsonWoCompare
// Both must be objects
assert.throws(function() {
bsonWoCompare({ x: 1 }, 1);
});
assert.throws(function() {
bsonWoCompare(1, { x: 1 });
});
assert.throws(function() {
@renctan
renctan / balancer_with_inconsistent_config.js
Last active December 19, 2015 00:39
Slightly modified test from SERVER-10015 (originally written by Greg)
//
// Tests whether the balancer continues with inconsistent chunks
//
var options = {separateConfig : true, sync : true};
var st = new ShardingTest({shards : 2, mongos : 1, other : options});
st.stopBalancer();
@renctan
renctan / update3.js
Last active December 18, 2015 08:19
Pick one scenario to run by removing the comments at the end of the script.
var st = new ShardingTest({ shards: 2 });
st.adminCommand({ enablesharding: "test" });
st.adminCommand({ shardcollection: "test.col0", key: { a: 1, b: 1 }});
st.adminCommand({ shardcollection: "test.col1", key: { 'x.a': 1 }});
var db = st.s.getDB( "test" );
var col = db.getCollection( "col0" );
var dotCol = db.getCollection( "col1" );
@renctan
renctan / squash.h
Created May 2, 2013 15:02
Proof of concept for generalized chunk range squashing. Note: T compiles for both ChunkType (needs to define specialized rangeIsNewer) and TagsType.
namespace mongo {
template <typename T>
bool rangeIsNewer(const T* lhs, const T* rhs);
/**
* Given a list of ranges (note: must be sorted by min), outputs the operations needed
* to squash the the overlapping ranges such that the list of ranges will not overlap
* one another.
*
* The caller owns the pointer to both the input and output vectors. The method guarantees
@renctan
renctan / fail_point_micro_bench.cpp
Created December 5, 2012 20:19
Failpoint microbenchmark scripts
/**
* Copyright (C) 2012 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program 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
@renctan
renctan / bench.patch
Created December 3, 2012 22:20
Failpoint benchmarking scripts
diff --git a/src/mongo/SConscript b/src/mongo/SConscript
index e23047f..95465ca 100644
--- a/src/mongo/SConscript
+++ b/src/mongo/SConscript
@@ -700,3 +700,9 @@ env.Alias("clientBuild", ['#buildscripts/build_and_test_client.py',
'$PYTHON ${SOURCES[0]} ${SOURCES[2]} ${EXTRAPATH and "--extrapath"} $EXTRAPATH'
)
env.AlwaysBuild("clientBuild")
+
+bench_fp = env.Install('#/', env.Program('bench_fp',
@renctan
renctan / fuzzer.py
Created August 4, 2012 19:38
Answer for Problem Set#4
#! /usr/bin/python
# A simple test that modifies random bytes of an existing dump file created
# from mongodump and runs mongorestore against a running mongod process on
# the default port
import random
import string
import subprocess
import time
// based from: https://gist.github.com/3fcf2a1c8583416c6ef9
var host = "replicaset.local";
var rsName = 'rs';
/**
* @return the connection string of the bridged replica set.
*/
var getBridgedConnection = function (startDestPort, startBridgePort, delays) {
var bridgeHosts = [];