Skip to content

Commit f1dac3a

Browse files
committed
optimize pgext serve and rewrite with go-sqlite
1 parent 8c8d496 commit f1dac3a

20 files changed

Lines changed: 2268 additions & 1240 deletions

.goreleaser.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: 2
22

33
env:
4-
- CGO_ENABLED=1
4+
- CGO_ENABLED=0
55

66
before:
77
hooks:
@@ -20,9 +20,6 @@ builds:
2020
- arm64
2121
ldflags:
2222
- -s -w
23-
- -extldflags "-static"
24-
flags:
25-
- -a
2623

2724
archives:
2825
- id: pgext

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Path : Makefile
77
# Copyright (C) 2019-2025 Ruohang Feng
88
#==============================================================#
9-
VERSION=v0.7.2
9+
VERSION=v1.0.0
1010
default: v d
1111

1212
PGURL="postgres:///data"
@@ -112,10 +112,10 @@ gen-mdx:
112112
@echo "Extension MDX files generated in content/docs/ext/"
113113

114114
arm:
115-
CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -a -ldflags "$(LD_FLAGS) -extldflags '-static'" -o pgext
115+
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "$(LD_FLAGS)" -o pgext
116116
upx pgext
117117
amd:
118-
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -o pgext
118+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o pgext
119119
upx pgext
120120

121121
# inventory

cli/confgen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ func GetConfigConstants() *ConfigConstants {
876876
{"agensgraph", "agensgraph-$v", "agensgraph-$v"},
877877
{"polardb", "polardb-$v", "polardb-$v"},
878878
{"openhalo", "openhalodb-$v", "openhalodb-$v"},
879-
{"ivorysql", "ivorysql5", "ivorysql-5"},
879+
{"ivorysql", "ivorysql-$v", "ivorysql-$v"},
880880
{"babelfish", "babelfish-$v", "babelfish-$v"},
881881
{"orioledb", "orioledb-$v", "orioledb-$v"},
882882
{"pgedge", "pgedge-$v", "pgedge-$v"},

cli/parse_dnf.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"os"
1111

1212
"github.com/jackc/pgx/v5"
13-
_ "github.com/mattn/go-sqlite3"
1413
"github.com/sirupsen/logrus"
14+
_ "modernc.org/sqlite"
1515
)
1616

1717
// DNFParser handles parsing of DNF/YUM repository metadata
@@ -53,7 +53,7 @@ func (p *DNFParser) ParseRepository(repoID string, data []byte) (int, error) {
5353
tmpFile.Close()
5454

5555
// Open SQLite database
56-
sqliteDB, err := sql.Open("sqlite3", tmpPath+"?mode=ro")
56+
sqliteDB, err := sql.Open("sqlite", "file:"+tmpPath+"?mode=ro")
5757
if err != nil {
5858
return 0, fmt.Errorf("open sqlite: %w", err)
5959
}

cli/parse_dnf_test.go

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
package cli
2+
3+
import (
4+
"context"
5+
"database/sql"
6+
"os"
7+
"path/filepath"
8+
"testing"
9+
)
10+
11+
// dnfPrimarySchema mirrors the columns extractPackages reads from repodata primary.sqlite.
12+
const dnfPrimarySchema = `
13+
CREATE TABLE packages (
14+
pkgKey INTEGER PRIMARY KEY,
15+
pkgId TEXT,
16+
name TEXT,
17+
arch TEXT,
18+
version TEXT,
19+
epoch TEXT,
20+
release TEXT,
21+
summary TEXT,
22+
description TEXT,
23+
url TEXT,
24+
time_file INTEGER,
25+
time_build INTEGER,
26+
rpm_license TEXT,
27+
rpm_vendor TEXT,
28+
rpm_group TEXT,
29+
rpm_buildhost TEXT,
30+
rpm_sourcerpm TEXT,
31+
rpm_header_start INTEGER,
32+
rpm_header_end INTEGER,
33+
rpm_packager TEXT,
34+
size_package INTEGER,
35+
size_installed INTEGER,
36+
size_archive INTEGER,
37+
location_href TEXT,
38+
location_base TEXT,
39+
checksum_type TEXT
40+
)`
41+
42+
// makeDNFPrimary builds a primary.sqlite file and returns its raw bytes.
43+
func makeDNFPrimary(t *testing.T, inserts ...string) []byte {
44+
t.Helper()
45+
path := filepath.Join(t.TempDir(), "primary.sqlite")
46+
db, err := sql.Open("sqlite", path)
47+
if err != nil {
48+
t.Fatalf("open sqlite: %v", err)
49+
}
50+
if _, err := db.Exec(dnfPrimarySchema); err != nil {
51+
t.Fatalf("create schema: %v", err)
52+
}
53+
for _, stmt := range inserts {
54+
if _, err := db.Exec(stmt); err != nil {
55+
t.Fatalf("insert: %v", err)
56+
}
57+
}
58+
if err := db.Close(); err != nil {
59+
t.Fatalf("close sqlite: %v", err)
60+
}
61+
data, err := os.ReadFile(path)
62+
if err != nil {
63+
t.Fatalf("read sqlite file: %v", err)
64+
}
65+
return data
66+
}
67+
68+
func TestDNFParserExtractPackages(t *testing.T) {
69+
data := makeDNFPrimary(t,
70+
`INSERT INTO packages (pkgKey, pkgId, name, arch, version, epoch, release,
71+
summary, url, time_build, rpm_license, rpm_sourcerpm,
72+
size_package, location_href, checksum_type)
73+
VALUES (1, 'abc123', 'pg_duckdb_18', 'x86_64', '1.1.2', '0', '1PGDG.rhel9',
74+
'DuckDB embedded in Postgres', 'https://github.com/duckdb/pg_duckdb', 1750000000,
75+
'MIT', 'pg_duckdb_18-1.1.2-1PGDG.rhel9.src.rpm',
76+
12345678, 'pg_duckdb_18-1.1.2-1PGDG.rhel9.x86_64.rpm', 'sha256')`,
77+
`INSERT INTO packages (pkgKey, pkgId, name) VALUES (2, 'def456', 'sparse-pkg')`,
78+
)
79+
80+
tmp := filepath.Join(t.TempDir(), "extract.sqlite")
81+
if err := os.WriteFile(tmp, data, 0644); err != nil {
82+
t.Fatalf("write temp sqlite: %v", err)
83+
}
84+
db, err := sql.Open("sqlite", "file:"+tmp+"?mode=ro")
85+
if err != nil {
86+
t.Fatalf("open sqlite ro: %v", err)
87+
}
88+
defer db.Close()
89+
90+
parser := newDNFParser(context.Background(), liveTable("dnf"), false)
91+
packages, err := parser.extractPackages(db)
92+
if err != nil {
93+
t.Fatalf("extractPackages: %v", err)
94+
}
95+
if len(packages) != 2 {
96+
t.Fatalf("got %d packages, want 2", len(packages))
97+
}
98+
99+
full := packages[0]
100+
if full.Name != "pg_duckdb_18" || full.PkgKey != 1 || full.PkgId != "abc123" {
101+
t.Fatalf("unexpected identity: %+v", full)
102+
}
103+
if !full.Version.Valid || full.Version.String != "1.1.2" {
104+
t.Fatalf("version = %+v, want 1.1.2", full.Version)
105+
}
106+
if !full.TimeBuild.Valid || full.TimeBuild.Int64 != 1750000000 {
107+
t.Fatalf("time_build = %+v, want 1750000000", full.TimeBuild)
108+
}
109+
if !full.SizePackage.Valid || full.SizePackage.Int64 != 12345678 {
110+
t.Fatalf("size_package = %+v, want 12345678", full.SizePackage)
111+
}
112+
113+
sparse := packages[1]
114+
if sparse.Name != "sparse-pkg" {
115+
t.Fatalf("sparse name = %q", sparse.Name)
116+
}
117+
if sparse.Arch.Valid || sparse.Summary.Valid || sparse.TimeBuild.Valid || sparse.SizePackage.Valid {
118+
t.Fatalf("sparse row should scan as NULLs: %+v", sparse)
119+
}
120+
121+
// mode=ro must reject writes
122+
if _, err := db.Exec(`INSERT INTO packages (pkgKey, pkgId, name) VALUES (3, 'x', 'y')`); err == nil {
123+
t.Fatal("write on mode=ro connection should fail")
124+
}
125+
}
126+
127+
func TestDNFParserParseRepositoryEmpty(t *testing.T) {
128+
// An empty packages table returns before any PostgreSQL access,
129+
// exercising the temp-file write and read-only DSN open path.
130+
data := makeDNFPrimary(t)
131+
parser := newDNFParser(context.Background(), liveTable("dnf"), false)
132+
count, err := parser.ParseRepository("test-repo", data)
133+
if err != nil {
134+
t.Fatalf("ParseRepository: %v", err)
135+
}
136+
if count != 0 {
137+
t.Fatalf("count = %d, want 0", count)
138+
}
139+
}

content/release/infra.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ weight: 400
66

77
Check [Infra Repo](/repo/infra) for usage instructions.
88

9+
## 2026-07-24
10+
11+
| Name | Old | New | Comment |
12+
|:------------------------|:--------------|:--------------|:-------------------------------------------|
13+
| etcd | 3.7.0 | 3.7.1 | |
14+
| redis-exporter | 1.87.0 | 1.88.0 | |
15+
| victoria-traces | 0.9.4 | 0.10.0 | |
16+
| rustfs | 1.0.0-beta.10 | 1.0.0-beta.11 | Prerelease line; preview releases excluded |
17+
| uv | 0.11.31 | 0.11.32 | |
18+
| pg-hardstorage | 1.0.13 | 1.0.16 | Direct-download artifacts |
19+
| code-server | 4.129.0 | 4.130.0 | Direct-download artifacts |
20+
| cloudflared | 2026.7.2 | 2026.7.3 | Direct-download artifacts |
21+
922
## 2026-07-23
1023

1124
| Name | Old | New | Comment |

content/release/infra.zh.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ weight: 400
77
参阅 [Infra 仓库](/zh/repo/infra),了解如何使用 Infra 仓库。
88

99

10+
## 2026-07-24
11+
12+
| 名称 | 旧值 | 新值 | 备注 |
13+
|:----------------------|:--------------|:--------------|:-------------------------|
14+
| etcd | 3.7.0 | 3.7.1 | |
15+
| redis-exporter | 1.87.0 | 1.88.0 | |
16+
| victoria-traces | 0.9.4 | 0.10.0 | |
17+
| rustfs | 1.0.0-beta.10 | 1.0.0-beta.11 | 预发布版本线;排除 preview 版本 |
18+
| uv | 0.11.31 | 0.11.32 | |
19+
| pg-hardstorage | 1.0.13 | 1.0.16 | 直链构建产物更新 |
20+
| code-server | 4.129.0 | 4.130.0 | 直链构建产物更新 |
21+
| cloudflared | 2026.7.2 | 2026.7.3 | 直链构建产物更新 |
22+
1023
## 2026-07-23
1124

1225
| 名称 | 旧值 | 新值 | 备注 |

go.mod

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,65 @@ go 1.26.2
44

55
require (
66
github.com/jackc/pgx/v5 v5.9.2
7-
github.com/mattn/go-sqlite3 v1.14.44
7+
github.com/lib/pq v1.12.3
88
github.com/sirupsen/logrus v1.9.4
99
github.com/spf13/cobra v1.10.2
10-
golang.org/x/sync v0.20.0
10+
github.com/spf13/pflag v1.0.10
11+
golang.org/x/sync v0.21.0
12+
modernc.org/sqlite v1.54.0
13+
www.velocidex.com/golang/velociraptor v0.77.1
14+
www.velocidex.com/golang/vfilter v0.0.0-20260604071755-26b8340c4bb8
1115
)
1216

1317
require (
14-
github.com/imfing/hextra v0.12.3-0.20260427194839-6ee265e06df7 // indirect
18+
github.com/Showmax/go-fqdn v1.0.0 // indirect
19+
github.com/Velocidex/json v0.0.0-20220224052537-92f3c0326e5a // indirect
20+
github.com/Velocidex/ordereddict v0.0.0-20250821063524-02dc06e46238 // indirect
21+
github.com/Velocidex/ttlcache/v2 v2.9.1-0.20240517145123-a3f45e86e130 // indirect
22+
github.com/Velocidex/yaml/v2 v2.2.8 // indirect
23+
github.com/alecthomas/participle v0.7.1 // indirect
24+
github.com/alecthomas/repr v0.5.2 // indirect
25+
github.com/beorn7/perks v1.0.1 // indirect
26+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
27+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
28+
github.com/dustin/go-humanize v1.0.1 // indirect
29+
github.com/ebitengine/purego v0.8.3 // indirect
30+
github.com/go-errors/errors v1.4.2 // indirect
31+
github.com/go-ole/go-ole v1.2.6 // indirect
32+
github.com/google/uuid v1.6.0 // indirect
33+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect
1534
github.com/inconshreveable/mousetrap v1.1.0 // indirect
1635
github.com/jackc/pgpassfile v1.0.0 // indirect
1736
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
1837
github.com/jackc/puddle/v2 v2.2.2 // indirect
19-
github.com/spf13/pflag v1.0.10 // indirect
20-
golang.org/x/sys v0.43.0 // indirect
21-
golang.org/x/text v0.36.0 // indirect
38+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
39+
github.com/mattn/go-isatty v0.0.20 // indirect
40+
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
41+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
42+
github.com/ncruces/go-strftime v1.0.0 // indirect
43+
github.com/pkg/errors v0.9.1 // indirect
44+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
45+
github.com/prometheus/client_golang v1.23.2 // indirect
46+
github.com/prometheus/client_model v0.6.2 // indirect
47+
github.com/prometheus/common v0.67.5 // indirect
48+
github.com/prometheus/procfs v0.20.1 // indirect
49+
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
50+
github.com/shirou/gopsutil/v4 v4.25.1 // indirect
51+
github.com/tklauser/go-sysconf v0.3.12 // indirect
52+
github.com/tklauser/numcpus v0.6.1 // indirect
53+
github.com/valyala/fastjson v1.6.4 // indirect
54+
github.com/yusufpapurcu/wmi v1.2.4 // indirect
55+
go.yaml.in/yaml/v2 v2.4.4 // indirect
56+
golang.org/x/mod v0.37.0 // indirect
57+
golang.org/x/net v0.55.0 // indirect
58+
golang.org/x/sys v0.46.0 // indirect
59+
golang.org/x/text v0.38.0 // indirect
60+
google.golang.org/genproto/googleapis/api v0.0.0-20260226221140-a57be14db171 // indirect
61+
google.golang.org/genproto/googleapis/rpc v0.0.0-20260523011958-0a33c5d7ca68 // indirect
62+
google.golang.org/grpc v1.81.1 // indirect
63+
google.golang.org/protobuf v1.36.11 // indirect
64+
gopkg.in/yaml.v3 v3.0.1 // indirect
65+
modernc.org/libc v1.74.1 // indirect
66+
modernc.org/mathutil v1.7.1 // indirect
67+
modernc.org/memory v1.11.0 // indirect
2268
)

0 commit comments

Comments
 (0)