Created
June 20, 2017 21:04
-
-
Save nirbhayc/fa63658700af366512f6c41e6a2dba8e to your computer and use it in GitHub Desktop.
(Blog) Find the largest event in a binary log file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
@File : largest_event.go | |
@Description : Find the largest event in a binary log file. | |
@Usage : ./largest_event.go -file=<binary log file> | |
*/ | |
package main | |
import ( | |
"flag" | |
"fmt" | |
"github.com/vaquita/mysql" | |
"os" | |
) | |
func main() { | |
var ( | |
b mysql.Binlog | |
dsn string | |
eventName string | |
eventSize uint32 | |
file string | |
) | |
flag.StringVar(&file, "file", "/tmp/master-bin.000001", | |
"Binary log file (absolute path)") | |
flag.Parse() | |
dsn = fmt.Sprint("file://", file) | |
// Open a binary log handle | |
if err := b.Connect(dsn); err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
// Start reading from the specified binary log file | |
if err := b.Begin(); err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
// Close the binary log handle | |
defer b.Close() | |
// Iterate through the events | |
for b.Next() { | |
re, err := b.RawEvent() | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
if re.Size() > eventSize { | |
eventSize = re.Size() | |
eventName = re.Name() | |
} | |
} | |
fmt.Println("Event :", eventName) | |
fmt.Println("Size :", eventSize) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment