Debug logging

This commit is contained in:
Till Faelligen 2023-01-03 07:44:47 +01:00
parent b9d947e438
commit 539781a51a
No known key found for this signature in database
GPG key ID: ACCDC9606D472758
3 changed files with 20 additions and 9 deletions

View file

@ -19,6 +19,7 @@ import (
"context" "context"
"database/sql" "database/sql"
"encoding/json" "encoding/json"
"fmt"
"github.com/lib/pq" "github.com/lib/pq"
"github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal"
@ -291,11 +292,14 @@ func (s *currentRoomStateStatements) SelectCurrentState(
pq.StringArray(excludeEventIDs), pq.StringArray(excludeEventIDs),
) )
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("SelectCurrentState failed: %w", err)
} }
defer internal.CloseAndLogIfError(ctx, rows, "selectCurrentState: rows.close() failed") defer internal.CloseAndLogIfError(ctx, rows, "selectCurrentState: rows.close() failed")
res, err := rowsToEvents(rows)
return rowsToEvents(rows) if err != nil {
return nil, fmt.Errorf("rowsToEvents failed: %w", err)
}
return res, nil
} }
func (s *currentRoomStateStatements) DeleteRoomStateByEventID( func (s *currentRoomStateStatements) DeleteRoomStateByEventID(

View file

@ -19,6 +19,7 @@ import (
"context" "context"
"database/sql" "database/sql"
"encoding/json" "encoding/json"
"fmt"
"sort" "sort"
"github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal"
@ -412,12 +413,12 @@ func (s *outputRoomEventsStatements) SelectRecentEvents(
eventFilter.Limit+1, eventFilter.Limit+1,
) )
if err != nil { if err != nil {
return nil, false, err return nil, false, fmt.Errorf("SelectRecentEvents failed: %w", err)
} }
defer internal.CloseAndLogIfError(ctx, rows, "selectRecentEvents: rows.close() failed") defer internal.CloseAndLogIfError(ctx, rows, "selectRecentEvents: rows.close() failed")
events, err := rowsToStreamEvents(rows) events, err := rowsToStreamEvents(rows)
if err != nil { if err != nil {
return nil, false, err return nil, false, fmt.Errorf("rowsToStreamEvents failed: %w", err)
} }
if chronologicalOrder { if chronologicalOrder {
// The events need to be returned from oldest to latest, which isn't // The events need to be returned from oldest to latest, which isn't

View file

@ -95,12 +95,18 @@ func (p *PDUStreamProvider) CompleteSync(
} }
// Build up a /sync response. Add joined rooms. // Build up a /sync response. Add joined rooms.
for _, roomID := range joinedRoomIDs { req.Log.WithField("rooms", len(joinedRoomIDs)).Debug("getting join response for rooms")
s := time.Now()
for i, roomID := range joinedRoomIDs {
jr, jerr := p.getJoinResponseForCompleteSync( jr, jerr := p.getJoinResponseForCompleteSync(
ctx, snapshot, roomID, r, &stateFilter, &eventFilter, req.WantFullState, req.Device, false, ctx, snapshot, roomID, r, &stateFilter, &eventFilter, req.WantFullState, req.Device, false,
) )
if jerr != nil { if jerr != nil {
req.Log.WithError(jerr).Error("p.getJoinResponseForCompleteSync failed") req.Log.WithError(jerr).WithContext(ctx).WithFields(logrus.Fields{
"failed_after": time.Since(s),
"room_id": roomID,
"collected_rooms": i,
}).Error("p.getJoinResponseForCompleteSync failed")
if ctxErr := req.Context.Err(); ctxErr != nil || jerr == sql.ErrTxDone { if ctxErr := req.Context.Err(); ctxErr != nil || jerr == sql.ErrTxDone {
return from return from
} }
@ -540,7 +546,7 @@ func (p *PDUStreamProvider) getJoinResponseForCompleteSync(
} }
backwardTopologyPos, backwardStreamPos, err = snapshot.PositionInTopology(ctx, event.EventID()) backwardTopologyPos, backwardStreamPos, err = snapshot.PositionInTopology(ctx, event.EventID())
if err != nil { if err != nil {
return return jr, fmt.Errorf("PositionInTopology failed: %w", err)
} }
prevBatch = &types.TopologyToken{ prevBatch = &types.TopologyToken{
Depth: backwardTopologyPos, Depth: backwardTopologyPos,
@ -609,7 +615,7 @@ func (p *PDUStreamProvider) lazyLoadMembers(
filter.Types = &[]string{gomatrixserverlib.MRoomMember} filter.Types = &[]string{gomatrixserverlib.MRoomMember}
memberships, err := snapshot.GetStateEventsForRoom(ctx, roomID, &filter) memberships, err := snapshot.GetStateEventsForRoom(ctx, roomID, &filter)
if err != nil { if err != nil {
return stateEvents, err return stateEvents, fmt.Errorf("(lazyLoadMembers) GetStateEventsForRoom failed: %w", err)
} }
// cache the membership events // cache the membership events
for _, membership := range memberships { for _, membership := range memberships {