mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-21 05:43:09 -06:00
s/QueryBackfill/PerformBackfill/g
This commit is contained in:
parent
25cd2dd1c9
commit
0459285e33
|
|
@ -37,7 +37,7 @@ func Backfill(
|
||||||
roomID string,
|
roomID string,
|
||||||
cfg *config.Dendrite,
|
cfg *config.Dendrite,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
var res api.QueryBackfillResponse
|
var res api.PerformBackfillResponse
|
||||||
var eIDs []string
|
var eIDs []string
|
||||||
var limit string
|
var limit string
|
||||||
var exists bool
|
var exists bool
|
||||||
|
|
@ -68,7 +68,7 @@ func Backfill(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate the request.
|
// Populate the request.
|
||||||
req := api.QueryBackfillRequest{
|
req := api.PerformBackfillRequest{
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
// we don't know who the successors are for these events, which won't
|
// we don't know who the successors are for these events, which won't
|
||||||
// be a problem because we don't use that information when servicing /backfill requests,
|
// be a problem because we don't use that information when servicing /backfill requests,
|
||||||
|
|
@ -87,8 +87,8 @@ func Backfill(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query the roomserver.
|
// Query the roomserver.
|
||||||
if err = rsAPI.QueryBackfill(httpReq.Context(), &req, &res); err != nil {
|
if err = rsAPI.PerformBackfill(httpReq.Context(), &req, &res); err != nil {
|
||||||
util.GetLogger(httpReq.Context()).WithError(err).Error("query.QueryBackfill failed")
|
util.GetLogger(httpReq.Context()).WithError(err).Error("query.PerformBackfill failed")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,10 +89,10 @@ type RoomserverInternalAPI interface {
|
||||||
) error
|
) error
|
||||||
|
|
||||||
// Query a given amount (or less) of events prior to a given set of events.
|
// Query a given amount (or less) of events prior to a given set of events.
|
||||||
QueryBackfill(
|
PerformBackfill(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *QueryBackfillRequest,
|
request *PerformBackfillRequest,
|
||||||
response *QueryBackfillResponse,
|
response *PerformBackfillResponse,
|
||||||
) error
|
) error
|
||||||
|
|
||||||
// Asks for the default room version as preferred by the server.
|
// Asks for the default room version as preferred by the server.
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PerformJoinRequest struct {
|
type PerformJoinRequest struct {
|
||||||
|
|
@ -22,3 +23,31 @@ type PerformLeaveRequest struct {
|
||||||
|
|
||||||
type PerformLeaveResponse struct {
|
type PerformLeaveResponse struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PerformBackfillRequest is a request to PerformBackfill.
|
||||||
|
type PerformBackfillRequest struct {
|
||||||
|
// The room to backfill
|
||||||
|
RoomID string `json:"room_id"`
|
||||||
|
// A map of backwards extremity event ID to a list of its prev_event IDs.
|
||||||
|
BackwardsExtremities map[string][]string `json:"backwards_extremities"`
|
||||||
|
// The maximum number of events to retrieve.
|
||||||
|
Limit int `json:"limit"`
|
||||||
|
// The server interested in the events.
|
||||||
|
ServerName gomatrixserverlib.ServerName `json:"server_name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrevEventIDs returns the prev_event IDs of all backwards extremities, de-duplicated in a lexicographically sorted order.
|
||||||
|
func (r *PerformBackfillRequest) PrevEventIDs() []string {
|
||||||
|
var prevEventIDs []string
|
||||||
|
for _, pes := range r.BackwardsExtremities {
|
||||||
|
prevEventIDs = append(prevEventIDs, pes...)
|
||||||
|
}
|
||||||
|
prevEventIDs = util.UniqueStrings(prevEventIDs)
|
||||||
|
return prevEventIDs
|
||||||
|
}
|
||||||
|
|
||||||
|
// PerformBackfillResponse is a response to PerformBackfill.
|
||||||
|
type PerformBackfillResponse struct {
|
||||||
|
// Missing events, arbritrary order.
|
||||||
|
Events []gomatrixserverlib.HeaderedEvent `json:"events"`
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// QueryLatestEventsAndStateRequest is a request to QueryLatestEventsAndState
|
// QueryLatestEventsAndStateRequest is a request to QueryLatestEventsAndState
|
||||||
|
|
@ -204,34 +203,6 @@ type QueryStateAndAuthChainResponse struct {
|
||||||
AuthChainEvents []gomatrixserverlib.HeaderedEvent `json:"auth_chain_events"`
|
AuthChainEvents []gomatrixserverlib.HeaderedEvent `json:"auth_chain_events"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryBackfillRequest is a request to QueryBackfill.
|
|
||||||
type QueryBackfillRequest struct {
|
|
||||||
// The room to backfill
|
|
||||||
RoomID string `json:"room_id"`
|
|
||||||
// A map of backwards extremity event ID to a list of its prev_event IDs.
|
|
||||||
BackwardsExtremities map[string][]string `json:"backwards_extremities"`
|
|
||||||
// The maximum number of events to retrieve.
|
|
||||||
Limit int `json:"limit"`
|
|
||||||
// The server interested in the events.
|
|
||||||
ServerName gomatrixserverlib.ServerName `json:"server_name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PrevEventIDs returns the prev_event IDs of all backwards extremities, de-duplicated in a lexicographically sorted order.
|
|
||||||
func (r *QueryBackfillRequest) PrevEventIDs() []string {
|
|
||||||
var prevEventIDs []string
|
|
||||||
for _, pes := range r.BackwardsExtremities {
|
|
||||||
prevEventIDs = append(prevEventIDs, pes...)
|
|
||||||
}
|
|
||||||
prevEventIDs = util.UniqueStrings(prevEventIDs)
|
|
||||||
return prevEventIDs
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryBackfillResponse is a response to QueryBackfill.
|
|
||||||
type QueryBackfillResponse struct {
|
|
||||||
// Missing events, arbritrary order.
|
|
||||||
Events []gomatrixserverlib.HeaderedEvent `json:"events"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryRoomVersionCapabilitiesRequest asks for the default room version
|
// QueryRoomVersionCapabilitiesRequest asks for the default room version
|
||||||
type QueryRoomVersionCapabilitiesRequest struct{}
|
type QueryRoomVersionCapabilitiesRequest struct{}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -441,11 +441,11 @@ func (r *RoomserverInternalAPI) QueryMissingEvents(
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryBackfill implements api.RoomServerQueryAPI
|
// PerformBackfill implements api.RoomServerQueryAPI
|
||||||
func (r *RoomserverInternalAPI) QueryBackfill(
|
func (r *RoomserverInternalAPI) PerformBackfill(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.QueryBackfillRequest,
|
request *api.PerformBackfillRequest,
|
||||||
response *api.QueryBackfillResponse,
|
response *api.PerformBackfillResponse,
|
||||||
) error {
|
) error {
|
||||||
// if we are requesting the backfill then we need to do a federation hit
|
// 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
|
// TODO: we could be more sensible and fetch as many events we already have then request the rest
|
||||||
|
|
@ -489,7 +489,7 @@ func (r *RoomserverInternalAPI) QueryBackfill(
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RoomserverInternalAPI) backfillViaFederation(ctx context.Context, req *api.QueryBackfillRequest, res *api.QueryBackfillResponse) error {
|
func (r *RoomserverInternalAPI) backfillViaFederation(ctx context.Context, req *api.PerformBackfillRequest, res *api.PerformBackfillResponse) error {
|
||||||
roomVer, err := r.DB.GetRoomVersionForRoom(ctx, req.RoomID)
|
roomVer, err := r.DB.GetRoomVersionForRoom(ctx, req.RoomID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("backfillViaFederation: unknown room version for room %s : %w", req.RoomID, err)
|
return fmt.Errorf("backfillViaFederation: unknown room version for room %s : %w", req.RoomID, err)
|
||||||
|
|
@ -647,7 +647,7 @@ func (r *RoomserverInternalAPI) scanEventTree(
|
||||||
var pre string
|
var pre string
|
||||||
|
|
||||||
// TODO: add tests for this function to ensure it meets the contract that callers expect (and doc what that is supposed to be)
|
// TODO: add tests for this function to ensure it meets the contract that callers expect (and doc what that is supposed to be)
|
||||||
// Currently, callers like QueryBackfill will call scanEventTree with a pre-populated `visited` map, assuming that by doing
|
// Currently, callers like PerformBackfill will call scanEventTree with a pre-populated `visited` map, assuming that by doing
|
||||||
// so means that the events in that map will NOT be returned from this function. That is not currently true, resulting in
|
// so means that the events in that map will NOT be returned from this function. That is not currently true, resulting in
|
||||||
// duplicate events being sent in response to /backfill requests.
|
// duplicate events being sent in response to /backfill requests.
|
||||||
initialIgnoreList := make(map[string]bool, len(visited))
|
initialIgnoreList := make(map[string]bool, len(visited))
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,9 @@ const (
|
||||||
RoomserverInputRoomEventsPath = "/roomserver/inputRoomEvents"
|
RoomserverInputRoomEventsPath = "/roomserver/inputRoomEvents"
|
||||||
|
|
||||||
// Perform operations
|
// Perform operations
|
||||||
RoomserverPerformJoinPath = "/roomserver/performJoin"
|
RoomserverPerformJoinPath = "/roomserver/performJoin"
|
||||||
RoomserverPerformLeavePath = "/roomserver/performLeave"
|
RoomserverPerformLeavePath = "/roomserver/performLeave"
|
||||||
|
RoomserverPerformBackfillPath = "/roomserver/performBackfill"
|
||||||
|
|
||||||
// Query operations
|
// Query operations
|
||||||
RoomserverQueryLatestEventsAndStatePath = "/roomserver/queryLatestEventsAndState"
|
RoomserverQueryLatestEventsAndStatePath = "/roomserver/queryLatestEventsAndState"
|
||||||
|
|
@ -36,7 +37,6 @@ const (
|
||||||
RoomserverQueryServerAllowedToSeeEventPath = "/roomserver/queryServerAllowedToSeeEvent"
|
RoomserverQueryServerAllowedToSeeEventPath = "/roomserver/queryServerAllowedToSeeEvent"
|
||||||
RoomserverQueryMissingEventsPath = "/roomserver/queryMissingEvents"
|
RoomserverQueryMissingEventsPath = "/roomserver/queryMissingEvents"
|
||||||
RoomserverQueryStateAndAuthChainPath = "/roomserver/queryStateAndAuthChain"
|
RoomserverQueryStateAndAuthChainPath = "/roomserver/queryStateAndAuthChain"
|
||||||
RoomserverQueryBackfillPath = "/roomserver/queryBackfill"
|
|
||||||
RoomserverQueryRoomVersionCapabilitiesPath = "/roomserver/queryRoomVersionCapabilities"
|
RoomserverQueryRoomVersionCapabilitiesPath = "/roomserver/queryRoomVersionCapabilities"
|
||||||
RoomserverQueryRoomVersionForRoomPath = "/roomserver/queryRoomVersionForRoom"
|
RoomserverQueryRoomVersionForRoomPath = "/roomserver/queryRoomVersionForRoom"
|
||||||
)
|
)
|
||||||
|
|
@ -274,16 +274,16 @@ func (h *httpRoomserverInternalAPI) QueryStateAndAuthChain(
|
||||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryBackfill implements RoomServerQueryAPI
|
// PerformBackfill implements RoomServerQueryAPI
|
||||||
func (h *httpRoomserverInternalAPI) QueryBackfill(
|
func (h *httpRoomserverInternalAPI) PerformBackfill(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.QueryBackfillRequest,
|
request *api.PerformBackfillRequest,
|
||||||
response *api.QueryBackfillResponse,
|
response *api.PerformBackfillResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryBackfill")
|
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformBackfill")
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
|
|
||||||
apiURL := h.roomserverURL + RoomserverQueryBackfillPath
|
apiURL := h.roomserverURL + RoomserverPerformBackfillPath
|
||||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -165,14 +165,14 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
internalAPIMux.Handle(
|
internalAPIMux.Handle(
|
||||||
RoomserverQueryBackfillPath,
|
RoomserverPerformBackfillPath,
|
||||||
internal.MakeInternalAPI("QueryBackfill", func(req *http.Request) util.JSONResponse {
|
internal.MakeInternalAPI("PerformBackfill", func(req *http.Request) util.JSONResponse {
|
||||||
var request api.QueryBackfillRequest
|
var request api.PerformBackfillRequest
|
||||||
var response api.QueryBackfillResponse
|
var response api.PerformBackfillResponse
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||||
return util.ErrorResponse(err)
|
return util.ErrorResponse(err)
|
||||||
}
|
}
|
||||||
if err := r.QueryBackfill(req.Context(), &request, &response); err != nil {
|
if err := r.PerformBackfill(req.Context(), &request, &response); err != nil {
|
||||||
return util.ErrorResponse(err)
|
return util.ErrorResponse(err)
|
||||||
}
|
}
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
||||||
|
|
|
||||||
|
|
@ -375,15 +375,15 @@ func (e eventsByDepth) Less(i, j int) bool {
|
||||||
// Returns an error if there was an issue with retrieving the list of servers in
|
// Returns an error if there was an issue with retrieving the list of servers in
|
||||||
// the room or sending the request.
|
// the room or sending the request.
|
||||||
func (r *messagesReq) backfill(roomID string, backwardsExtremities map[string][]string, limit int) ([]gomatrixserverlib.HeaderedEvent, error) {
|
func (r *messagesReq) backfill(roomID string, backwardsExtremities map[string][]string, limit int) ([]gomatrixserverlib.HeaderedEvent, error) {
|
||||||
var res api.QueryBackfillResponse
|
var res api.PerformBackfillResponse
|
||||||
err := r.rsAPI.QueryBackfill(context.Background(), &api.QueryBackfillRequest{
|
err := r.rsAPI.PerformBackfill(context.Background(), &api.PerformBackfillRequest{
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
BackwardsExtremities: backwardsExtremities,
|
BackwardsExtremities: backwardsExtremities,
|
||||||
Limit: limit,
|
Limit: limit,
|
||||||
ServerName: r.cfg.Matrix.ServerName,
|
ServerName: r.cfg.Matrix.ServerName,
|
||||||
}, &res)
|
}, &res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("QueryBackfill failed: %w", err)
|
return nil, fmt.Errorf("PerformBackfill failed: %w", err)
|
||||||
}
|
}
|
||||||
util.GetLogger(r.ctx).WithField("new_events", len(res.Events)).Info("Storing new events from backfill")
|
util.GetLogger(r.ctx).WithField("new_events", len(res.Events)).Info("Storing new events from backfill")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue