All sorts of debugging information and tweaks - still no joy

This commit is contained in:
Neil Alexander 2020-01-14 15:17:14 +00:00
parent 7a7be4f0ac
commit 49ff4d6d8f
12 changed files with 139 additions and 19 deletions

View file

@ -18,6 +18,7 @@ package sqlite3
import (
"context"
"database/sql"
"fmt"
"github.com/matrix-org/dendrite/roomserver/types"
)
@ -76,6 +77,7 @@ func (s *eventJSONStatements) bulkSelectEventJSON(
) ([]eventJSONPair, error) {
rows, err := s.bulkSelectEventJSONStmt.QueryContext(ctx, eventNIDsAsArray(eventNIDs))
if err != nil {
fmt.Println("bulkSelectEventJSON s.bulkSelectEventJSONStmt.QueryContext:", err)
return nil, err
}
defer rows.Close() // nolint: errcheck
@ -90,6 +92,7 @@ func (s *eventJSONStatements) bulkSelectEventJSON(
result := &results[i]
var eventNID int64
if err := rows.Scan(&eventNID, &result.EventJSON); err != nil {
fmt.Println("bulkSelectEventJSON rows.Scan:", err)
return nil, err
}
result.EventNID = types.EventNID(eventNID)

View file

@ -18,6 +18,7 @@ package sqlite3
import (
"context"
"database/sql"
"fmt"
"github.com/lib/pq"
"github.com/matrix-org/dendrite/common"
@ -95,6 +96,11 @@ func (s *eventStateKeyStatements) insertEventStateKeyNID(
selectStmt := common.TxStmt(txn, s.insertEventStateKeyNIDResultStmt)
if _, err = insertStmt.ExecContext(ctx, eventStateKey); err == nil {
err = selectStmt.QueryRowContext(ctx).Scan(&eventStateKeyNID)
if err != nil {
fmt.Println("insertEventStateKeyNID selectStmt.QueryRowContext:", err)
}
} else {
fmt.Println("insertEventStateKeyNID insertStmt.ExecContext:", err)
}
return types.EventStateKeyNID(eventStateKeyNID), err
}
@ -105,6 +111,9 @@ func (s *eventStateKeyStatements) selectEventStateKeyNID(
var eventStateKeyNID int64
stmt := common.TxStmt(txn, s.selectEventStateKeyNIDStmt)
err := stmt.QueryRowContext(ctx, eventStateKey).Scan(&eventStateKeyNID)
if err != nil {
fmt.Println("selectEventStateKeyNID stmt.QueryRowContext:", err)
}
return types.EventStateKeyNID(eventStateKeyNID), err
}
@ -115,6 +124,7 @@ func (s *eventStateKeyStatements) bulkSelectEventStateKeyNID(
ctx, pq.StringArray(eventStateKeys),
)
if err != nil {
fmt.Println("bulkSelectEventStateKeyNID s.bulkSelectEventStateKeyNIDStmt.QueryContext:", err)
return nil, err
}
defer rows.Close() // nolint: errcheck
@ -123,6 +133,7 @@ func (s *eventStateKeyStatements) bulkSelectEventStateKeyNID(
var stateKey string
var stateKeyNID int64
if err := rows.Scan(&stateKey, &stateKeyNID); err != nil {
fmt.Println("bulkSelectEventStateKeyNID rows.Scan:", err)
return nil, err
}
result[stateKey] = types.EventStateKeyNID(stateKeyNID)
@ -139,6 +150,7 @@ func (s *eventStateKeyStatements) bulkSelectEventStateKey(
}
rows, err := s.bulkSelectEventStateKeyStmt.QueryContext(ctx, nIDs)
if err != nil {
fmt.Println("bulkSelectEventStateKey s.bulkSelectEventStateKeyStmt.QueryContext:", err)
return nil, err
}
defer rows.Close() // nolint: errcheck
@ -147,6 +159,7 @@ func (s *eventStateKeyStatements) bulkSelectEventStateKey(
var stateKey string
var stateKeyNID int64
if err := rows.Scan(&stateKey, &stateKeyNID); err != nil {
fmt.Println("bulkSelectEventStateKey rows.Scan:", err)
return nil, err
}
result[types.EventStateKeyNID(stateKeyNID)] = stateKey

View file

@ -247,6 +247,9 @@ func (s *eventStatements) updateEventState(
ctx context.Context, eventNID types.EventNID, stateNID types.StateSnapshotNID,
) error {
_, err := s.updateEventStateStmt.ExecContext(ctx, int64(eventNID), int64(stateNID))
if err != nil {
fmt.Println("updateEventState s.updateEventStateStmt.ExecContext:", err)
}
return err
}
@ -255,12 +258,20 @@ func (s *eventStatements) selectEventSentToOutput(
) (sentToOutput bool, err error) {
stmt := common.TxStmt(txn, s.selectEventSentToOutputStmt)
err = stmt.QueryRowContext(ctx, int64(eventNID)).Scan(&sentToOutput)
//err = s.selectEventSentToOutputStmt.QueryRowContext(ctx, int64(eventNID)).Scan(&sentToOutput)
if err != nil {
fmt.Println("selectEventSentToOutput stmt.QueryRowContext:", err)
}
return
}
func (s *eventStatements) updateEventSentToOutput(ctx context.Context, txn *sql.Tx, eventNID types.EventNID) error {
stmt := common.TxStmt(txn, s.updateEventSentToOutputStmt)
_, err := stmt.ExecContext(ctx, int64(eventNID))
//_, err := s.updateEventSentToOutputStmt.ExecContext(ctx, int64(eventNID))
if err != nil {
fmt.Println("updateEventSentToOutput stmt.QueryRowContext:", err)
}
return err
}
@ -269,6 +280,9 @@ func (s *eventStatements) selectEventID(
) (eventID string, err error) {
stmt := common.TxStmt(txn, s.selectEventIDStmt)
err = stmt.QueryRowContext(ctx, int64(eventNID)).Scan(&eventID)
if err != nil {
fmt.Println("selectEventID stmt.QueryRowContext:", err)
}
return
}
@ -276,8 +290,9 @@ func (s *eventStatements) bulkSelectStateAtEventAndReference(
ctx context.Context, txn *sql.Tx, eventNIDs []types.EventNID,
) ([]types.StateAtEventAndReference, error) {
stmt := common.TxStmt(txn, s.bulkSelectStateAtEventAndReferenceStmt)
rows, err := stmt.QueryContext(ctx, eventNIDsAsArray(eventNIDs))
rows, err := stmt.QueryContext(ctx, sqliteIn(eventNIDsAsArray(eventNIDs)))
if err != nil {
fmt.Println("bulkSelectStateAtEventAndREference stmt.QueryContext:", err)
return nil, err
}
defer rows.Close() // nolint: errcheck
@ -295,6 +310,7 @@ func (s *eventStatements) bulkSelectStateAtEventAndReference(
if err = rows.Scan(
&eventTypeNID, &eventStateKeyNID, &eventNID, &stateSnapshotNID, &eventID, &eventSHA256,
); err != nil {
fmt.Println("bulkSelectStateAtEventAndReference rows.Scan:", err)
return nil, err
}
result := &results[i]
@ -314,8 +330,9 @@ func (s *eventStatements) bulkSelectStateAtEventAndReference(
func (s *eventStatements) bulkSelectEventReference(
ctx context.Context, eventNIDs []types.EventNID,
) ([]gomatrixserverlib.EventReference, error) {
rows, err := s.bulkSelectEventReferenceStmt.QueryContext(ctx, eventNIDsAsArray(eventNIDs))
rows, err := s.bulkSelectEventReferenceStmt.QueryContext(ctx, sqliteIn(eventNIDsAsArray(eventNIDs)))
if err != nil {
fmt.Println("bulkSelectEventReference s.bulkSelectEventReferenceStmt.QueryContext:", err)
return nil, err
}
defer rows.Close() // nolint: errcheck
@ -324,6 +341,7 @@ func (s *eventStatements) bulkSelectEventReference(
for ; rows.Next(); i++ {
result := &results[i]
if err = rows.Scan(&result.EventID, &result.EventSHA256); err != nil {
fmt.Println("bulkSelectEventReference rows.Scan:", err)
return nil, err
}
}
@ -335,8 +353,9 @@ func (s *eventStatements) bulkSelectEventReference(
// bulkSelectEventID returns a map from numeric event ID to string event ID.
func (s *eventStatements) bulkSelectEventID(ctx context.Context, eventNIDs []types.EventNID) (map[types.EventNID]string, error) {
rows, err := s.bulkSelectEventIDStmt.QueryContext(ctx, eventNIDsAsArray(eventNIDs))
rows, err := s.bulkSelectEventIDStmt.QueryContext(ctx, sqliteIn(eventNIDsAsArray(eventNIDs)))
if err != nil {
fmt.Println("bulkSelectEventID s.bulkSelectEventIDStmt.QueryContext:", err)
return nil, err
}
defer rows.Close() // nolint: errcheck
@ -346,6 +365,7 @@ func (s *eventStatements) bulkSelectEventID(ctx context.Context, eventNIDs []typ
var eventNID int64
var eventID string
if err = rows.Scan(&eventNID, &eventID); err != nil {
fmt.Println("bulkSelectEventID rows.Scan:", err)
return nil, err
}
results[types.EventNID(eventNID)] = eventID
@ -361,6 +381,7 @@ func (s *eventStatements) bulkSelectEventID(ctx context.Context, eventNIDs []typ
func (s *eventStatements) bulkSelectEventNID(ctx context.Context, eventIDs []string) (map[string]types.EventNID, error) {
rows, err := s.bulkSelectEventNIDStmt.QueryContext(ctx, pq.StringArray(eventIDs))
if err != nil {
fmt.Println("bulkSelectEventNID s.bulkSelectEventNIDStmt.QueryContext:", err)
return nil, err
}
defer rows.Close() // nolint: errcheck
@ -369,6 +390,7 @@ func (s *eventStatements) bulkSelectEventNID(ctx context.Context, eventIDs []str
var eventID string
var eventNID int64
if err = rows.Scan(&eventID, &eventNID); err != nil {
fmt.Println("bulkSelectEventNID rows.Scan:", err)
return nil, err
}
results[eventID] = types.EventNID(eventNID)
@ -379,8 +401,9 @@ func (s *eventStatements) bulkSelectEventNID(ctx context.Context, eventIDs []str
func (s *eventStatements) selectMaxEventDepth(ctx context.Context, eventNIDs []types.EventNID) (int64, error) {
var result int64
stmt := s.selectMaxEventDepthStmt
err := stmt.QueryRowContext(ctx, eventNIDsAsArray(eventNIDs)).Scan(&result)
err := stmt.QueryRowContext(ctx, sqliteIn(eventNIDsAsArray(eventNIDs))).Scan(&result)
if err != nil {
fmt.Println("selectMaxEventDepth stmt.QueryRowContext:", err)
return 0, err
}
return result, nil

View file

@ -18,6 +18,7 @@ package sqlite3
import (
"context"
"database/sql"
"fmt"
"github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/roomserver/types"
@ -83,14 +84,18 @@ func (s *inviteStatements) insertInviteEvent(
targetUserNID, senderUserNID types.EventStateKeyNID,
inviteEventJSON []byte,
) (bool, error) {
result, err := common.TxStmt(txn, s.insertInviteEventStmt).ExecContext(
stmt := common.TxStmt(txn, s.insertInviteEventStmt)
defer stmt.Close()
result, err := stmt.ExecContext(
ctx, inviteEventID, roomNID, targetUserNID, senderUserNID, inviteEventJSON,
)
if err != nil {
fmt.Println("insertInviteEvent common.TxStmt.ExecContext:", err)
return false, err
}
count, err := result.RowsAffected()
if err != nil {
fmt.Println("insertInviteEvent result.RowsAffected:", err)
return false, err
}
return count != 0, nil
@ -103,12 +108,14 @@ func (s *inviteStatements) updateInviteRetired(
stmt := common.TxStmt(txn, s.updateInviteRetiredStmt)
rows, err := stmt.QueryContext(ctx, roomNID, targetUserNID)
if err != nil {
fmt.Println("updateInviteRetired stmt.QueryContext:", err)
return nil, err
}
defer (func() { err = rows.Close() })()
for rows.Next() {
var inviteEventID string
if err := rows.Scan(&inviteEventID); err != nil {
fmt.Println("updateInviteRetired rows.Scan:", err)
return nil, err
}
eventIDs = append(eventIDs, inviteEventID)
@ -125,6 +132,7 @@ func (s *inviteStatements) selectInviteActiveForUserInRoom(
ctx, targetUserNID, roomNID,
)
if err != nil {
fmt.Println("selectInviteActiveForUserInRoom s.selectInviteActiveForUserInRoomStmt.QueryContext:", err)
return nil, err
}
defer rows.Close() // nolint: errcheck
@ -132,6 +140,7 @@ func (s *inviteStatements) selectInviteActiveForUserInRoom(
for rows.Next() {
var senderUserNID int64
if err := rows.Scan(&senderUserNID); err != nil {
fmt.Println("selectInviteActiveForUserInRoom rows.Scan:", err)
return nil, err
}
result = append(result, types.EventStateKeyNID(senderUserNID))

View file

@ -18,6 +18,7 @@ package sqlite3
import (
"context"
"database/sql"
"fmt"
"github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/roomserver/types"
@ -100,6 +101,9 @@ func (s *membershipStatements) insertMembership(
) error {
stmt := common.TxStmt(txn, s.insertMembershipStmt)
_, err := stmt.ExecContext(ctx, roomNID, targetUserNID)
if err != nil {
fmt.Println("insertMembership stmt.ExecContent:", err)
}
return err
}
@ -107,9 +111,13 @@ func (s *membershipStatements) selectMembershipForUpdate(
ctx context.Context,
txn *sql.Tx, roomNID types.RoomNID, targetUserNID types.EventStateKeyNID,
) (membership membershipState, err error) {
err = common.TxStmt(txn, s.selectMembershipForUpdateStmt).QueryRowContext(
stmt := common.TxStmt(txn, s.selectMembershipForUpdateStmt)
err = stmt.QueryRowContext(
ctx, roomNID, targetUserNID,
).Scan(&membership)
if err != nil {
fmt.Println("selectMembershipForUpdate common.TxStmt.Scan:", err)
}
return
}
@ -120,6 +128,9 @@ func (s *membershipStatements) selectMembershipFromRoomAndTarget(
err = s.selectMembershipFromRoomAndTargetStmt.QueryRowContext(
ctx, roomNID, targetUserNID,
).Scan(&membership, &eventNID)
if err != nil {
fmt.Println("selectMembershipForUpdate s.selectMembershipFromRoomAndTargetStmt.QueryRowContext:", err)
}
return
}
@ -128,12 +139,14 @@ func (s *membershipStatements) selectMembershipsFromRoom(
) (eventNIDs []types.EventNID, err error) {
rows, err := s.selectMembershipsFromRoomStmt.QueryContext(ctx, roomNID)
if err != nil {
fmt.Println("selectMembershipsFromRoom s.selectMembershipsFromRoomStmt.QueryContext:", err)
return
}
for rows.Next() {
var eNID types.EventNID
if err = rows.Scan(&eNID); err != nil {
fmt.Println("selectMembershipsFromRoom rows.Scan:", err)
return
}
eventNIDs = append(eventNIDs, eNID)
@ -147,12 +160,14 @@ func (s *membershipStatements) selectMembershipsFromRoomAndMembership(
stmt := s.selectMembershipsFromRoomAndMembershipStmt
rows, err := stmt.QueryContext(ctx, roomNID, membership)
if err != nil {
fmt.Println("selectMembershipsFromRoomAndMembership stmt.QueryContext:", err)
return
}
for rows.Next() {
var eNID types.EventNID
if err = rows.Scan(&eNID); err != nil {
fmt.Println("selectMembershipsFromRoomAndMembership rows.Scan:", err)
return
}
eventNIDs = append(eventNIDs, eNID)
@ -166,8 +181,12 @@ func (s *membershipStatements) updateMembership(
senderUserNID types.EventStateKeyNID, membership membershipState,
eventNID types.EventNID,
) error {
_, err := common.TxStmt(txn, s.updateMembershipStmt).ExecContext(
stmt := common.TxStmt(txn, s.updateMembershipStmt)
_, err := stmt.ExecContext(
ctx, roomNID, targetUserNID, senderUserNID, membership, eventNID,
)
if err != nil {
fmt.Println("updateMembership common.TxStmt.ExecContent:", err)
}
return err
}

View file

@ -18,6 +18,7 @@ package sqlite3
import (
"context"
"database/sql"
"fmt"
"github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/roomserver/types"
@ -78,6 +79,9 @@ func (s *previousEventStatements) insertPreviousEvent(
_, err := stmt.ExecContext(
ctx, previousEventID, previousEventReferenceSHA256, int64(eventNID),
)
if err != nil {
fmt.Println("insertPreviousEvent stmt.ExecContext:", err)
}
return err
}
@ -88,5 +92,8 @@ func (s *previousEventStatements) selectPreviousEventExists(
) error {
var ok int64
stmt := common.TxStmt(txn, s.selectPreviousEventExistsStmt)
defer func() {
fmt.Println("SELECTED PREVIOUS EVENT EXISTS", ok)
}()
return stmt.QueryRowContext(ctx, eventID, eventReferenceSHA256).Scan(&ok)
}

View file

@ -18,6 +18,7 @@ package sqlite3
import (
"context"
"database/sql"
"fmt"
)
const roomAliasesSchema = `
@ -76,6 +77,9 @@ func (s *roomAliasesStatements) insertRoomAlias(
ctx context.Context, alias string, roomID string, creatorUserID string,
) (err error) {
_, err = s.insertRoomAliasStmt.ExecContext(ctx, alias, roomID, creatorUserID)
if err != nil {
fmt.Println("insertRoomAlias s.insertRoomAliasStmt.ExecContent:", err)
}
return
}
@ -95,12 +99,14 @@ func (s *roomAliasesStatements) selectAliasesFromRoomID(
aliases = []string{}
rows, err := s.selectAliasesFromRoomIDStmt.QueryContext(ctx, roomID)
if err != nil {
fmt.Println("selectAliasesFromRoomID s.selectAliasesFromRoomIDStmt.QueryContext:", err)
return
}
for rows.Next() {
var alias string
if err = rows.Scan(&alias); err != nil {
fmt.Println("selectAliasesFromRoomID rows.Scan:", err)
return
}

View file

@ -18,6 +18,7 @@ package sqlite3
import (
"context"
"database/sql"
"fmt"
"github.com/lib/pq"
"github.com/matrix-org/dendrite/common"
@ -90,6 +91,11 @@ func (s *roomStatements) insertRoomNID(
resultStmt := common.TxStmt(txn, s.insertRoomNIDResultStmt)
if _, err = insertStmt.ExecContext(ctx, roomID); err == nil {
err = resultStmt.QueryRowContext(ctx).Scan(&roomNID)
if err != nil {
fmt.Println("insertRoomNID resultStmt.QueryRowContext:", err)
}
} else {
fmt.Println("insertRoomNID insertStmt.ExecContext:", err)
}
return types.RoomNID(roomNID), err
}
@ -100,6 +106,9 @@ func (s *roomStatements) selectRoomNID(
var roomNID int64
stmt := common.TxStmt(txn, s.selectRoomNIDStmt)
err := stmt.QueryRowContext(ctx, roomID).Scan(&roomNID)
if err != nil {
fmt.Println("selectRoomNID stmt.QueryRowContext:", err)
}
return types.RoomNID(roomNID), err
}
@ -111,6 +120,7 @@ func (s *roomStatements) selectLatestEventNIDs(
stmt := s.selectLatestEventNIDsStmt
err := stmt.QueryRowContext(ctx, int64(roomNID)).Scan(&nids, &stateSnapshotNID)
if err != nil {
fmt.Println("selectLatestEventNIDs stmt.QueryRowContext:", err)
return nil, 0, err
}
eventNIDs := make([]types.EventNID, len(nids))
@ -129,6 +139,7 @@ func (s *roomStatements) selectLatestEventsNIDsForUpdate(
stmt := common.TxStmt(txn, s.selectLatestEventNIDsForUpdateStmt)
err := stmt.QueryRowContext(ctx, int64(roomNID)).Scan(&nids, &lastEventSentNID, &stateSnapshotNID)
if err != nil {
fmt.Println("selectLatestEventsNIDsForUpdate stmt.QueryRowContext:", err)
return nil, 0, 0, err
}
eventNIDs := make([]types.EventNID, len(nids))
@ -154,5 +165,8 @@ func (s *roomStatements) updateLatestEventNIDs(
int64(lastEventSentNID),
int64(stateSnapshotNID),
)
if err != nil {
fmt.Println("updateLatestEventNIDs stmt.ExecContext:", err)
}
return err
}

View file

@ -42,7 +42,7 @@ const insertStateDataSQL = "" +
const selectNextStateBlockNIDSQL = `
SELECT COALESCE((
SELECT seq AS state_block_nid FROM sqlite_sequence
SELECT seq+1 AS state_block_nid FROM sqlite_sequence
WHERE name = 'roomserver_state_block'), 0
) AS state_block_nid
`
@ -106,6 +106,7 @@ func (s *stateBlockStatements) bulkInsertStateData(
int64(entry.EventNID),
)
if err != nil {
fmt.Println("bulkInsertStateData s.insertStateDataStmt.ExecContext:", err)
return err
}
}
@ -127,8 +128,9 @@ func (s *stateBlockStatements) bulkSelectStateBlockEntries(
for i := range stateBlockNIDs {
nids[i] = int64(stateBlockNIDs[i])
}
rows, err := s.bulkSelectStateBlockEntriesStmt.QueryContext(ctx, pq.Int64Array(nids))
rows, err := s.bulkSelectStateBlockEntriesStmt.QueryContext(ctx, sqliteIn(pq.Int64Array(nids)))
if err != nil {
fmt.Println("bulkSelectStateBlockEntries s.bulkSelectStateBlockEntriesStmt.QueryContext:", err)
return nil, err
}
defer rows.Close() // nolint: errcheck
@ -148,8 +150,10 @@ func (s *stateBlockStatements) bulkSelectStateBlockEntries(
if err := rows.Scan(
&stateBlockNID, &eventTypeNID, &eventStateKeyNID, &eventNID,
); err != nil {
fmt.Println("bulkSelectStateBlockEntries rows.Scan:", err)
return nil, err
}
fmt.Println("state block NID", stateBlockNID, "event type NID", eventTypeNID, "event state key NID", eventStateKeyNID, "event NID", eventNID)
entry.EventTypeNID = types.EventTypeNID(eventTypeNID)
entry.EventStateKeyNID = types.EventStateKeyNID(eventStateKeyNID)
entry.EventNID = types.EventNID(eventNID)
@ -162,8 +166,8 @@ func (s *stateBlockStatements) bulkSelectStateBlockEntries(
}
current.StateEntries = append(current.StateEntries, entry)
}
if i != len(stateBlockNIDs) {
return nil, fmt.Errorf("storage: state data NIDs missing from the database (%d != %d)", i, len(stateBlockNIDs))
if i != len(nids) {
return nil, fmt.Errorf("storage: state data NIDs missing from the database (%d != %d)", i, len(nids))
}
return results, nil
}
@ -182,9 +186,10 @@ func (s *stateBlockStatements) bulkSelectFilteredStateBlockEntries(
ctx,
stateBlockNIDsAsArray(stateBlockNIDs),
eventTypeNIDArray,
eventStateKeyNIDArray,
sqliteIn(eventStateKeyNIDArray),
)
if err != nil {
fmt.Println("bulkSelectFilteredStateBlockEntries s.bulkSelectFilteredStateBlockEntriesStmt.QueryContext:", err)
return nil, err
}
defer rows.Close() // nolint: errcheck
@ -202,6 +207,7 @@ func (s *stateBlockStatements) bulkSelectFilteredStateBlockEntries(
if err := rows.Scan(
&stateBlockNID, &eventTypeNID, &eventStateKeyNID, &eventNID,
); err != nil {
fmt.Println("bulkSelectFilteredStateBlockEntries rows.Scan:", err)
return nil, err
}
entry.EventTypeNID = types.EventTypeNID(eventTypeNID)

View file

@ -77,6 +77,11 @@ func (s *stateSnapshotStatements) insertState(
}
if _, err = s.insertStateStmt.ExecContext(ctx, int64(roomNID), pq.Int64Array(nids)); err == nil {
err = s.insertStateResultStmt.QueryRowContext(ctx).Scan(&stateNID)
if err != nil {
fmt.Println("insertState s.insertStateResultStmt.QueryRowContext:", err)
}
} else {
fmt.Println("insertState s.insertStateStmt.ExecContext:", err)
}
return
}
@ -90,6 +95,7 @@ func (s *stateSnapshotStatements) bulkSelectStateBlockNIDs(
}
rows, err := s.bulkSelectStateBlockNIDsStmt.QueryContext(ctx, sqliteIn(pq.Int64Array(nids)))
if err != nil {
fmt.Println("bulkSelectStateBlockNIDs s.bulkSelectStateBlockNIDsStmt.QueryContext:", err)
return nil, err
}
defer rows.Close() // nolint: errcheck
@ -99,6 +105,7 @@ func (s *stateSnapshotStatements) bulkSelectStateBlockNIDs(
result := &results[i]
var stateBlockNIDs pq.Int64Array
if err := rows.Scan(&result.StateSnapshotNID, &stateBlockNIDs); err != nil {
fmt.Println("bulkSelectStateBlockNIDs rows.Scan:", err)
return nil, err
}
result.StateBlockNIDs = make([]types.StateBlockNID, len(stateBlockNIDs))

View file

@ -18,6 +18,8 @@ package sqlite3
import (
"context"
"database/sql"
"errors"
"fmt"
"net/url"
"github.com/matrix-org/dendrite/roomserver/api"
@ -39,16 +41,20 @@ func Open(dataSourceName string) (*Database, error) {
if err != nil {
return nil, err
}
var cs string
if uri.Opaque != "" { // file:filename.db
if d.db, err = sql.Open("sqlite3", uri.Opaque); err != nil {
return nil, err
}
cs = fmt.Sprintf("%s?cache=shared&_busy_timeout=9999999", uri.Opaque)
} else if uri.Path != "" { // file:///path/to/filename.db
cs = fmt.Sprintf("%s?cache=shared&_busy_timeout=9999999", uri.Path)
} else {
return nil, errors.New("no filename or path in connect string")
}
if uri.Path != "" { // file:///path/to/filename.db
if d.db, err = sql.Open("sqlite3", uri.Path); err != nil {
return nil, err
}
if d.db, err = sql.Open("sqlite3", cs); err != nil {
return nil, err
}
//d.db.Exec("PRAGMA journal_mode=WAL;")
//d.db.Exec("PRAGMA parser_trace = true;")
d.db.SetMaxOpenConns(1)
if err = d.statements.prepare(d.db); err != nil {
return nil, err
}

View file

@ -18,6 +18,7 @@ package sqlite3
import (
"context"
"database/sql"
"fmt"
)
const transactionsSchema = `
@ -66,6 +67,9 @@ func (s *transactionStatements) insertTransaction(
_, err = s.insertTransactionStmt.ExecContext(
ctx, transactionID, sessionID, userID, eventID,
)
if err != nil {
fmt.Println("insertTransaction s.insertTransactionStmt.ExecContent:", err)
}
return
}
@ -78,5 +82,8 @@ func (s *transactionStatements) selectTransactionEventID(
err = s.selectTransactionEventIDStmt.QueryRowContext(
ctx, transactionID, sessionID, userID,
).Scan(&eventID)
if err != nil {
fmt.Println("selectTransactionEventID s.selectTransactionEventIDStmt.QueryRowContext:", err)
}
return
}