func()

in origin/blobserver/server.go [718:761]


func (s *Server) startClusterUploadHandler(w http.ResponseWriter, r *http.Request) error {
	ctx, span := s.tracer.Start(r.Context(), "origin.start_upload",
		trace.WithSpanKind(trace.SpanKindServer),
		trace.WithAttributes(
			attribute.String("component", "origin"),
			attribute.String("operation", "start_cluster_upload"),
		),
	)
	defer span.End()

	d, err := httputil.ParseDigest(r, "digest")
	if err != nil {
		span.RecordError(err)
		span.SetStatus(codes.Error, "parse digest failed")
		return err
	}
	namespace, err := httputil.ParseParam(r, "namespace")
	if err != nil {
		span.RecordError(err)
		span.SetStatus(codes.Error, "parse namespace failed")
		return err
	}

	span.SetAttributes(
		attribute.String("namespace", namespace),
		attribute.String("blob.digest", d.Hex()),
	)

	log.WithTraceContext(ctx).With("namespace", namespace, "digest", d.Hex()).Info("Starting cluster upload")
	uid, err := s.uploader.start(d)
	if err != nil {
		span.RecordError(err)
		span.SetStatus(codes.Error, "start upload failed")
		log.WithTraceContext(ctx).With("namespace", namespace, "digest", d.Hex()).Warnf("Failed to start cluster upload: %s", err)
		return s.handleUploadConflict(ctx, err, namespace, d)
	}

	span.SetAttributes(attribute.String("upload.uid", uid))
	setUploadLocation(w, uid)
	w.WriteHeader(http.StatusOK)
	log.WithTraceContext(ctx).With("namespace", namespace, "digest", d.Hex(), "uid", uid).Info("Successfully started cluster upload")
	span.SetStatus(codes.Ok, "upload started")
	return nil
}