Write implements backend.Writer
(ctx context.Context, tenantID string, meta []*BlockMeta, compactedMeta []*CompactedBlockMeta)
| 132 | |
| 133 | // Write implements backend.Writer |
| 134 | func (w *writer) WriteTenantIndex(ctx context.Context, tenantID string, meta []*BlockMeta, compactedMeta []*CompactedBlockMeta) error { |
| 135 | // If meta and compactedMeta are empty, call delete the tenant index. |
| 136 | if len(meta) == 0 && len(compactedMeta) == 0 { |
| 137 | // Skip returning an error when the object is already deleted. |
| 138 | err := w.w.Delete(ctx, TenantIndexName, []string{tenantID}, nil) |
| 139 | if err != nil && !errors.Is(err, ErrDoesNotExist) { |
| 140 | return err |
| 141 | } |
| 142 | |
| 143 | err = w.w.Delete(ctx, TenantIndexNamePb, []string{tenantID}, nil) |
| 144 | if err != nil && !errors.Is(err, ErrDoesNotExist) { |
| 145 | return err |
| 146 | } |
| 147 | |
| 148 | return nil |
| 149 | } |
| 150 | |
| 151 | b := newTenantIndex(meta, compactedMeta) |
| 152 | |
| 153 | // Marshal and write the proto object. |
| 154 | indexBytesPb, err := b.marshalPb() |
| 155 | if err != nil { |
| 156 | return err |
| 157 | } |
| 158 | |
| 159 | err = w.w.Write(ctx, TenantIndexNamePb, KeyPath([]string{tenantID}), bytes.NewReader(indexBytesPb), int64(len(indexBytesPb)), nil) |
| 160 | if err != nil { |
| 161 | return err |
| 162 | } |
| 163 | |
| 164 | // Marshal and write the JSON object. |
| 165 | indexBytesJSON, err := b.marshal() |
| 166 | if err != nil { |
| 167 | return err |
| 168 | } |
| 169 | |
| 170 | return w.w.Write(ctx, TenantIndexName, KeyPath([]string{tenantID}), bytes.NewReader(indexBytesJSON), int64(len(indexBytesJSON)), nil) |
| 171 | } |
| 172 | |
| 173 | // Delete implements backend.Writer |
| 174 | func (w *writer) Delete(ctx context.Context, name string, keypath KeyPath) error { |