Fix backfill maybe

This commit is contained in:
Neil Alexander 2022-11-15 13:50:45 +00:00
parent b0c897c1d3
commit 0be99a3bdf
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
5 changed files with 15 additions and 12 deletions

View file

@ -124,7 +124,7 @@ func Backfill(
}
txn := gomatrixserverlib.Transaction{
Origin: cfg.Matrix.ServerName,
Origin: request.Destination(),
PDUs: eventJSONs,
OriginServerTS: gomatrixserverlib.AsTimestamp(time.Now()),
}

View file

@ -87,10 +87,10 @@ func NewRoomserverAPI(
Durable: base.Cfg.Global.JetStream.Durable("RoomserverInputConsumer"),
ServerACLs: serverACLs,
Queryer: &query.Queryer{
DB: roomserverDB,
Cache: base.Caches,
ServerName: base.Cfg.Global.ServerName,
ServerACLs: serverACLs,
DB: roomserverDB,
Cache: base.Caches,
IsLocalServerName: base.Cfg.Global.IsLocalServerName,
ServerACLs: serverACLs,
},
// perform-er structs get initialised when we have a federation sender to use
}

View file

@ -55,7 +55,7 @@ func (r *Backfiller) PerformBackfill(
// if we are requesting the backfill then we need to do a federation hit
// TODO: we could be more sensible and fetch as many events we already have then request the rest
// which is what the syncapi does already.
if !r.IsLocalServerName(request.ServerName) {
if r.IsLocalServerName(request.ServerName) {
return r.backfillViaFederation(ctx, request, response)
}
// someone else is requesting the backfill, try to service their request.
@ -120,8 +120,10 @@ func (r *Backfiller) backfillViaFederation(ctx context.Context, req *api.Perform
// Specifically the test "Outbound federation can backfill events"
events, err := gomatrixserverlib.RequestBackfill(
ctx, req.VirtualHost, requester,
r.KeyRing, req.RoomID, info.RoomVersion, req.PrevEventIDs(), 100)
r.KeyRing, req.RoomID, info.RoomVersion, req.PrevEventIDs(), 100,
)
if err != nil {
logrus.WithError(err).Errorf("gomatrixserverlib.RequestBackfill failed")
return err
}
logrus.WithField("room_id", req.RoomID).Infof("backfilled %d events", len(events))

View file

@ -37,10 +37,10 @@ import (
)
type Queryer struct {
DB storage.Database
Cache caching.RoomServerCaches
ServerName gomatrixserverlib.ServerName
ServerACLs *acls.ServerACLs
DB storage.Database
Cache caching.RoomServerCaches
IsLocalServerName func(gomatrixserverlib.ServerName) bool
ServerACLs *acls.ServerACLs
}
// QueryLatestEventsAndState implements api.RoomserverInternalAPI
@ -392,7 +392,7 @@ func (r *Queryer) QueryServerJoinedToRoom(
}
response.RoomExists = true
if request.ServerName == r.ServerName || request.ServerName == "" {
if r.IsLocalServerName(request.ServerName) || request.ServerName == "" {
response.IsInRoom, err = r.DB.GetLocalServerInRoom(ctx, info.RoomNID)
if err != nil {
return fmt.Errorf("r.DB.GetLocalServerInRoom: %w", err)

View file

@ -528,6 +528,7 @@ func (r *messagesReq) backfill(roomID string, backwardsExtremities map[string][]
BackwardsExtremities: backwardsExtremities,
Limit: limit,
ServerName: r.cfg.Matrix.ServerName,
VirtualHost: r.device.UserDomain(),
}, &res)
if err != nil {
return nil, fmt.Errorf("PerformBackfill failed: %w", err)