<commit_before>package event

import (
	"encoding/binary"
	"log"
	"os"
	"runtime"
	"sync"
	"time"

	"github.com/Sirupsen/logrus"
	"github.com/boltdb/bolt"
	"github.com/pquerna/ffjson/ffjson"
)

var (
	EVENT_BUCKET_NAME      = []byte("events")
	INCIDENT_BUCKET_NAME   = []byte("incidents")
	MANAGEMENT_BUCKET_NAME = []byte("management")
	INCIDENT_COUNT_NAME    = []byte("incident_count")
)

const (
	KEEP_ALIVE_SERVICE_NAME = "KeepAlive"
)

type Index struct {
	pool       *EncodingPool
	db         *bolt.DB
	dbFileName string
	keepAlives map[string]time.Time
	ka_lock    sync.RWMutex
}

func NewIndex(dbName string) *Index {
	db_wait := make(chan struct{})
	var db *bolt.DB
	var err error
	go func() {
		db, err = bolt.Open(dbName, 0600, nil)
		if err != nil {
			logrus.Fatal(err)
		}
		db_wait <- struct{}{}
	}()

	// if the db takes more than 100 miliseconds to open, fail out
	select {
	case <-time.After(100 * time.Millisecond):
		logrus.Fatalf("Unable to open db %s", dbName)
	case <-db_wait:
		logrus.Infof("Opened db %s", dbName)
	}

	err = db.Update(func(tx *bolt.Tx) error {
		logrus.Info("Setting up event bucket.")
		_, err := tx.CreateBucketIfNotExists(EVENT_BUCKET_NAME)
		if err != nil {
			return err
		}

		logrus.Info("Setting up management bucket.")
		_, err = tx.CreateBucketIfNotExists(MANAGEMENT_BUCKET_NAME)
		if err != nil {
			return err
		}

		logrus.Info("Setting up incident bucket.")
		_, err = tx.CreateBucketIfNotExists(INCIDENT_BUCKET_NAME)
		return err
	})

	if err != nil {
		logrus.Fatal(err)
	}

	return &Index{<commit_msg>allow for a 1 second timeout<commit_after>package event

import (
	"encoding/binary"
	"log"
	"os"
	"runtime"
	"sync"
	"time"

	"github.com/Sirupsen/logrus"
	"github.com/boltdb/bolt"
	"github.com/pquerna/ffjson/ffjson"
)

var (
	EVENT_BUCKET_NAME      = []byte("events")
	INCIDENT_BUCKET_NAME   = []byte("incidents")
	MANAGEMENT_BUCKET_NAME = []byte("management")
	INCIDENT_COUNT_NAME    = []byte("incident_count")
)

const (
	KEEP_ALIVE_SERVICE_NAME = "KeepAlive"
)

type Index struct {
	pool       *EncodingPool
	db         *bolt.DB
	dbFileName string
	keepAlives map[string]time.Time
	ka_lock    sync.RWMutex
}

func NewIndex(dbName string) *Index {
	db_wait := make(chan struct{})
	var db *bolt.DB
	var err error
	go func() {
		db, err = bolt.Open(dbName, 0600, nil)
		if err != nil {
			logrus.Fatal(err)
		}
		db_wait <- struct{}{}
	}()

	// if the db takes more than 100 miliseconds to open, fail out
	select {
	case <-time.After(1000 * time.Millisecond):
		logrus.Fatalf("Unable to open db %s", dbName)
	case <-db_wait:
		logrus.Infof("Opened db %s", dbName)
	}

	err = db.Update(func(tx *bolt.Tx) error {
		logrus.Info("Setting up event bucket.")
		_, err := tx.CreateBucketIfNotExists(EVENT_BUCKET_NAME)
		if err != nil {
			return err
		}

		logrus.Info("Setting up management bucket.")
		_, err = tx.CreateBucketIfNotExists(MANAGEMENT_BUCKET_NAME)
		if err != nil {
			return err
		}

		logrus.Info("Setting up incident bucket.")
		_, err = tx.CreateBucketIfNotExists(INCIDENT_BUCKET_NAME)
		return err
	})

	if err != nil {
		logrus.Fatal(err)
	}

	return &Index{
{'fraction_non_alphanumeric': 0.13209955328653478, 'fraction_numerical': 0.007019783024888321, 'mean_word_length': 3.7072072072072073, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6908782', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1205, 'n_words': 266}