Skip to content

Commit

Permalink
Adapt yproxy from yezzey 1.8.1. Do not fetch yezzey_expire_index (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
reshke authored Oct 31, 2024
1 parent 1ebc912 commit 269b67f
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ type DB struct {
oid pgtype.OID
}

type Ei struct {
reloid pgtype.OID
relfileoid pgtype.OID
expireLsn string
fqnmd5 string
type ExpireHint struct {
expireLsn string
x_path string
}

func (database *DatabaseHandler) populateIndex() {

}

func (database *DatabaseHandler) GetVirtualExpireIndexes(port uint64) (map[string]bool, map[string]uint64, error) { //TODO несколько баз
Expand All @@ -43,48 +45,50 @@ func (database *DatabaseHandler) GetVirtualExpireIndexes(port uint64) (map[strin
defer conn.Close() //error
ylogger.Zero.Debug().Msg("connected to database")

rows, err := conn.Query(`SELECT reloid, relfileoid, expire_lsn, fqnmd5 FROM yezzey.yezzey_expire_index WHERE expire_lsn != '0/0';`)
if err != nil {
return nil, nil, fmt.Errorf("unable to get ao/aocs tables %v", err) //fix
}
defer rows.Close()
ylogger.Zero.Debug().Msg("executed select")

c := make(map[string]uint64, 0)
for rows.Next() {
row := Ei{}
if err := rows.Scan(&row.reloid, &row.relfileoid, &row.expireLsn, &row.fqnmd5); err != nil {
return nil, nil, fmt.Errorf("unable to parse query output %v", err)
}

lsn, err := pgx.ParseLSN(row.expireLsn)
/* Todo: check that yezzey version >= 1.8.1 */
if false {
rows, err := conn.Query(`SELECT x_path, expire_lsn FROM yezzey.yezzey_expire_hint;`)
if err != nil {
return nil, nil, fmt.Errorf("unable to parse query output %v", err)
return nil, nil, fmt.Errorf("unable to get ao/aocs tables %v", err) //fix
}

ylogger.Zero.Debug().Str("file", fmt.Sprintf("%d_%d_%s_%d_", db.tablespace, db.oid, row.fqnmd5, row.relfileoid)).Msg("added file to ei")
c[fmt.Sprintf("%d_%d_%s_%d_", db.tablespace, db.oid, row.fqnmd5, row.relfileoid)] = lsn
defer rows.Close()
ylogger.Zero.Debug().Msg("executed select")

for rows.Next() {
row := ExpireHint{}
if err := rows.Scan(&row.x_path, &row.expireLsn); err != nil {
return nil, nil, fmt.Errorf("unable to parse query output %v", err)
}

lsn, err := pgx.ParseLSN(row.expireLsn)
if err != nil {
return nil, nil, fmt.Errorf("unable to parse query output %v", err)
}

ylogger.Zero.Debug().Str("x_path", row.x_path).Str("lsn", row.expireLsn).Msg("added file to expire hint")
c[row.x_path] = lsn
}
ylogger.Zero.Debug().Msg("fetched expire hint info")
}
ylogger.Zero.Debug().Msg("read 1")

rows2, err := conn.Query(`SELECT x_path FROM yezzey.yezzey_virtual_index;`)
if err != nil {
return nil, nil, fmt.Errorf("unable to get ao/aocs tables %v", err) //fix
}
defer rows2.Close()
ylogger.Zero.Debug().Msg("read 2")

c2 := make(map[string]bool, 0)
for rows2.Next() {
xpath := ""
if err := rows2.Scan(&xpath); err != nil {
return nil, nil, fmt.Errorf("unable to parse query output %v", err)
}
p2 := xpath
c2[p2] = true
ylogger.Zero.Debug().Str("file", p2).Msg("added")
c2[xpath] = true
ylogger.Zero.Debug().Str("x_path", xpath).Msg("added")
}
ylogger.Zero.Debug().Msg("read 3")
ylogger.Zero.Debug().Msg("fetched virtual index info")

return c2, c, err
}
Expand Down

0 comments on commit 269b67f

Please sign in to comment.