MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / initTables

Method initTables

internal/caches/list_file_db_sqlite.go:493–555  ·  view source on GitHub ↗

初始化

(times int)

Source from the content-addressed store, hash-verified

491
492// 初始化
493func (this *SQLiteFileListDB) initTables(times int) error {
494 {
495 // expiredAt - 过期时间,用来判断有无过期
496 // staleAt - 过时缓存最大时间,用来清理缓存
497 // 不对 hash 增加 unique 参数,是尽可能避免产生 malformed 错误
498 _, err := this.writeDB.Exec(`CREATE TABLE IF NOT EXISTS "` + this.itemsTableName + `" (
499 "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
500 "hash" varchar(32),
501 "key" varchar(1024),
502 "tag" varchar(64),
503 "headerSize" integer DEFAULT 0,
504 "bodySize" integer DEFAULT 0,
505 "metaSize" integer DEFAULT 0,
506 "expiredAt" integer DEFAULT 0,
507 "staleAt" integer DEFAULT 0,
508 "createdAt" integer DEFAULT 0,
509 "host" varchar(128),
510 "serverId" integer
511);
512
513DROP INDEX IF EXISTS "createdAt";
514DROP INDEX IF EXISTS "expiredAt";
515DROP INDEX IF EXISTS "serverId";
516
517CREATE INDEX IF NOT EXISTS "staleAt"
518ON "` + this.itemsTableName + `" (
519 "staleAt" ASC
520);
521
522CREATE INDEX IF NOT EXISTS "hash"
523ON "` + this.itemsTableName + `" (
524 "hash" ASC
525);
526`)
527
528 if err != nil {
529 // 忽略可以预期的错误
530 if strings.Contains(err.Error(), "duplicate column name") {
531 err = nil
532 }
533
534 // 尝试删除重建
535 if err != nil {
536 if times < 3 {
537 _, dropErr := this.writeDB.Exec(`DROP TABLE "` + this.itemsTableName + `"`)
538 if dropErr == nil {
539 return this.initTables(times + 1)
540 }
541 return this.WrapError(err)
542 }
543
544 return this.WrapError(err)
545 }
546 }
547 }
548
549 // 删除hits表
550 {

Callers 1

InitMethod · 0.95

Calls 4

WrapErrorMethod · 0.95
ExecMethod · 0.45
ContainsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected