forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
104938: pgrepl: implement the parser for the PostgreSQL replication protocol r=ZhouXing19 a=otan This commit implements parsing the [PG replication protocol syntax](https://www.postgresql.org/docs/current/protocol-replication.html) which is derived from the `.y` file from PG itself. We had to invent some new lexing protocols as the lexing mechanism is different to standard plpgsql/pgsql. This is in preparation for supporting pglogical within CRDB. Epic: https://cockroachlabs.atlassian.net/browse/CRDB-26486 Release note: None Co-authored-by: Oliver Tan <otan@cockroachlabs.com>
- Loading branch information
Showing
39 changed files
with
2,048 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "lsn", | ||
srcs = ["lsn.go"], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/sql/pgrepl/lsn", | ||
visibility = ["//visibility:public"], | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2023 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
// Package lsn contains logic for handling the pg_lsn type. | ||
package lsn | ||
|
||
import "fmt" | ||
|
||
type LSN uint64 | ||
|
||
func (lsn LSN) String() string { | ||
return fmt.Sprintf("%X/%X", uint32(lsn>>32), uint32(lsn)) | ||
} | ||
|
||
func ParseLSN(str string) (LSN, error) { | ||
var lo, hi uint32 | ||
if _, err := fmt.Sscanf(str, "%X/%X", &hi, &lo); err != nil { | ||
return 0, err | ||
} | ||
return (LSN(hi) << 32) | LSN(lo), nil | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Do not add environment-specific entries here (see the top-level .gitignore | ||
# for reasoning and alternatives). | ||
|
||
pgrepl.go | ||
y.output | ||
gen |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
|
||
sh_binary( | ||
name = "pgrepl-gen", | ||
srcs = ["//pkg/sql/lexbase:sql-gen.sh"], | ||
) | ||
|
||
# Define the target to auto-generate sql.go from the grammar file. | ||
genrule( | ||
name = "pgrepl-goyacc", | ||
srcs = [ | ||
"pgrepl.y", | ||
], | ||
outs = ["pgrepl.go"], | ||
cmd = """ | ||
export GOPATH=/nonexist-gopath | ||
$(location :pgrepl-gen) $(location pgrepl.y) pgrepl ""\ | ||
$(location pgrepl.go) $(location @org_golang_x_tools//cmd/goyacc) \ | ||
$(location @com_github_cockroachdb_gostdlib//x/tools/cmd/goimports) \ | ||
""", | ||
exec_tools = [ | ||
":pgrepl-gen", | ||
"@com_github_cockroachdb_gostdlib//x/tools/cmd/goimports", | ||
"@org_golang_x_tools//cmd/goyacc", | ||
], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
go_library( | ||
name = "pgreplparser", | ||
srcs = [ | ||
"lexer.go", | ||
"parser.go", | ||
"pgrepl.go", | ||
"pgreplparser.go", | ||
], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/sql/pgrepl/pgreplparser", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/sql/lexbase", | ||
"//pkg/sql/parser", | ||
"//pkg/sql/pgrepl/lsn", | ||
"//pkg/sql/pgrepl/pgrepltree", | ||
"//pkg/sql/pgwire/pgcode", | ||
"//pkg/sql/pgwire/pgerror", | ||
"//pkg/sql/sem/tree", | ||
"@com_github_cockroachdb_errors//:errors", | ||
"@com_github_cockroachdb_redact//:redact", # keep | ||
], | ||
) | ||
|
||
exports_files( | ||
[ | ||
"pgrepl.y", | ||
], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
go_test( | ||
name = "pgreplparser_test", | ||
srcs = [ | ||
"lexer_test.go", | ||
"parser_test.go", | ||
], | ||
args = ["-test.timeout=295s"], | ||
data = glob(["testdata/**"]), | ||
embed = [":pgreplparser"], | ||
deps = [ | ||
"//pkg/sql/pgrepl/lsn", | ||
"//pkg/sql/pgwire/pgerror", | ||
"//pkg/sql/sem/tree", | ||
"//pkg/testutils/datapathutils", | ||
"@com_github_cockroachdb_datadriven//:datadriven", | ||
"@com_github_stretchr_testify//assert", | ||
"@com_github_stretchr_testify//require", | ||
], | ||
) |
Oops, something went wrong.