Beispiel #1
0
//StartKeryxStream will start all the streams necessary to go from WAL entries to txn messages.
func (fs *FullStream) StartKeryxStream(serverVersion string, filters filters.MessageFilter, dataDir string, bufferWorkingDirectory string) (<-chan *message.Transaction, error) {
	walStream, err := streams.NewWalStream(dataDir)
	if err != nil {
		return nil, err
	}
	fs.walStream = walStream

	wal, err := fs.walStream.Start()
	if err != nil {
		return nil, err
	}

	txnBuffer := &streams.TxnBuffer{Filters: filters, WorkingDirectory: bufferWorkingDirectory, SchemaReader: fs.sr}
	buffered, err := txnBuffer.Start(wal)
	if err != nil {
		fs.Stop()
		return nil, err
	}

	populated := &streams.PopulatedMessageStream{Filters: filters, SchemaReader: fs.sr, MaxMessageCount: fs.MaxMessageCount}
	keryx, err := populated.Start(serverVersion, buffered)
	if err != nil {
		fs.Stop()
		return nil, err
	}

	return keryx, nil
}
Beispiel #2
0
//StartSummaryChannel sets up a keryx symmary stream and schema reader with the provided configuration and returns a channel
func StartSummaryChannel(ctx context.Context, serverVersion string, kc *Config) (<-chan message.TxnSummary, error) {
	schemaReader, err := pg.NewSchemaReader(kc.PGConnStrings, "postgres", 255)
	if err != nil {
		return nil, err
	}

	bufferWorkingDirectory, err := kc.GetBufferDirectoryOrTemp()
	if err != nil {
		return nil, err
	}

	walStream, err := streams.NewWalStream(kc.DataDir)
	if err != nil {
		return nil, err
	}

	wal, err := walStream.Start()
	if err != nil {
		return nil, err
	}

	go func() {
		<-ctx.Done()
		walStream.Stop()
	}()

	f := filters.Exclusive(schemaReader, kc.ExcludeRelations)
	if len(kc.IncludeRelations) > 0 {
		f = filters.Inclusive(schemaReader, kc.IncludeRelations)
	}

	txnBuffer := &streams.TxnBuffer{Filters: f, WorkingDirectory: bufferWorkingDirectory, SchemaReader: schemaReader}
	buffered, err := txnBuffer.Start(wal)
	if err != nil {
		walStream.Stop()
		return nil, err
	}

	return streams.SummaryStream{SchemaMetaInformation: schemaReader}.Start(serverVersion, buffered)
}