Skip to content

Instantly share code, notes, and snippets.

@agavra
Created March 6, 2024 20:36
Show Gist options
  • Select an option

  • Save agavra/494cc951b2c7b525d28b7105e0efc78b to your computer and use it in GitHub Desktop.

Select an option

Save agavra/494cc951b2c7b525d28b7105e0efc78b to your computer and use it in GitHub Desktop.
Race Condition Log Analyzer
import * as fs from 'fs';
import * as rd from 'readline'
function getKey(result: RegExpExecArray) {
return result[1] + '/' + result[3]
}
const regex = /\[(transaction_id_store-[0-9]+)] Flushing ([0-9]+) records with batchSize=[0-9]+ to remote \(offset=([0-9]+)/
const regex2 = /\[(transaction_id_store-[0-9]+)] Flushed ([0-9]+) records to [0-9]+ table partitions with offset ([0-9]+)/
const reader = rd.createInterface(fs.createReadStream('<log file>'))
const data = new Map<string, string>();
let validated = 0;
reader.on('line', (line: string) => {
const result = regex.exec(line)
if (result) {
data.set(getKey(result), result[2])
return
}
const result2 = regex2.exec(line)
if (result2) {
const key = getKey(result2)
const old = data.get(key)
if (!old) return;
const val = result2[2]
if (data.get(key) == val) {
if (validated % 10000 == 0) console.log(`Validated ${validated} entries`)
validated++;
data.delete(key)
} else {
console.log(`uh oh! Expected ${old} for ${key} but got ${val}`)
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment