round 1 of follow-up for metadata (#2277)
Some checks failed
build / build (push) Has been cancelled
ghcr / Build (push) Has been cancelled

* refactoring
* send an empty batch if necessary, as per spec
* don't broadcast no-op updates
* don't trim spaces before validating the key
* bump irctest to cover metadata
* replay existing metadata to reattaching always-on clients
* use canonicalized name everywhere
* use utils.SafeErrorParam in FAIL lines
* validate key names for sub
* fix error for METADATA CLEAR
* max-keys is enforced for channels as well
* remove unlimited configurations
* maintain the limit exactly without off-by-one cases
* add final channel registration check
This commit is contained in:
Shivaram Lingamneni 2025-06-18 00:22:49 -04:00 committed by GitHub
parent 4dcbc48159
commit 3b7db7fff7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 213 additions and 172 deletions

View file

@ -894,7 +894,7 @@ func (channel *Channel) GetMetadata(key string) (string, bool) {
return val, ok
}
func (channel *Channel) SetMetadata(key string, value string) {
func (channel *Channel) SetMetadata(key string, value string, limit int) (updated bool, err error) {
defer channel.MarkDirty(IncludeAllAttrs)
channel.stateMutex.Lock()
@ -904,7 +904,15 @@ func (channel *Channel) SetMetadata(key string, value string) {
channel.metadata = make(map[string]string)
}
channel.metadata[key] = value
existing, ok := channel.metadata[key]
if !ok && len(channel.metadata) >= limit {
return false, errLimitExceeded
}
updated = !ok || value != existing
if updated {
channel.metadata[key] = value
}
return updated, nil
}
func (channel *Channel) ListMetadata() map[string]string {
@ -914,13 +922,17 @@ func (channel *Channel) ListMetadata() map[string]string {
return maps.Clone(channel.metadata)
}
func (channel *Channel) DeleteMetadata(key string) {
func (channel *Channel) DeleteMetadata(key string) (updated bool) {
defer channel.MarkDirty(IncludeAllAttrs)
channel.stateMutex.Lock()
defer channel.stateMutex.Unlock()
delete(channel.metadata, key)
_, updated = channel.metadata[key]
if updated {
delete(channel.metadata, key)
}
return updated
}
func (channel *Channel) ClearMetadata() map[string]string {
@ -949,7 +961,7 @@ func (client *Client) GetMetadata(key string) (string, bool) {
return val, ok
}
func (client *Client) SetMetadata(key string, value string) {
func (client *Client) SetMetadata(key string, value string, limit int) (updated bool, err error) {
client.stateMutex.Lock()
defer client.stateMutex.Unlock()
@ -957,7 +969,15 @@ func (client *Client) SetMetadata(key string, value string) {
client.metadata = make(map[string]string)
}
client.metadata[key] = value
existing, ok := client.metadata[key]
if !ok && len(client.metadata) >= limit {
return false, errLimitExceeded
}
updated = !ok || value != existing
if updated {
client.metadata[key] = value
}
return updated, nil
}
func (client *Client) ListMetadata() map[string]string {
@ -967,11 +987,15 @@ func (client *Client) ListMetadata() map[string]string {
return maps.Clone(client.metadata)
}
func (client *Client) DeleteMetadata(key string) {
func (client *Client) DeleteMetadata(key string) (updated bool) {
client.stateMutex.Lock()
defer client.stateMutex.Unlock()
delete(client.metadata, key)
_, updated = client.metadata[key]
if updated {
delete(client.metadata, key)
}
return updated
}
func (client *Client) ClearMetadata() map[string]string {