Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support decimal number type keys in maps #140

Merged

Conversation

aksentyev
Copy link

@aksentyev aksentyev commented Apr 5, 2018

It is strange that bson package cannot resolve such cases, e.g. encoding/json package uses encoding.TextMarshaler/encoding.TextUnmarshaler interfaces for this, in spite of json does not support non string keys. I've done some changes to be able to use maps with decimal number type keys in models with this adapter.

domodwyer and others added 4 commits February 13, 2018 11:21
Periodic cluster synchronisation calls isMaster() which currently resends the
"client" metadata every call - the spec specifies:

	isMaster commands issued after the initial connection handshake MUST NOT
	contain handshake arguments

	https://github.com/mongodb/specifications/blob/master/source/mongodb-handshake/handshake.rst#connection-handshake

This hotfix prevents subsequent isMaster calls from sending the client metadata
again - fixes globalsign#101 and fixes globalsign#103.

Thanks to @changwoo-nam @qhenkart @canthefason @jyoon17 for spotting the initial
issue, opening tickets, and having the problem debugged with a PoC fix before I
even woke up.
* Brings in a patch on having flusher not suppress errors. (globalsign#81)

go-mgo#360

* Fallback to JSON tags when BSON tag isn't present (globalsign#91)

* Fallback to JSON tags when BSON tag isn't present


Cleanup.

* Add test to demonstrate tagging fallback.

- Test coverage for tagging test.

* socket: only send client metadata once per socket

Periodic cluster synchronisation calls isMaster() which currently resends the
"client" metadata every call - the spec specifies:

	isMaster commands issued after the initial connection handshake MUST NOT
	contain handshake arguments

	https://github.com/mongodb/specifications/blob/master/source/mongodb-handshake/handshake.rst#connection-handshake

This hotfix prevents subsequent isMaster calls from sending the client metadata
again - fixes globalsign#101 and fixes globalsign#103.

Thanks to @changwoo-nam @qhenkart @canthefason @jyoon17 for spotting the initial
issue, opening tickets, and having the problem debugged with a PoC fix before I
even woke up.

* Cluster abended test 254 (globalsign#100)

* Add a test that mongo Server gets their abended reset as necessary.

See https://github.com/go-mgo/mgo/issues/254 and
https://github.com/go-mgo/mgo/pull/255/files

* Include the patch from Issue 255.

This brings in a test which fails without the patch, and passes with the
patch. Still to be tested, manual tcpkill of a socket.

* changeStream support (globalsign#97)

Add $changeStream support

* readme: credit @peterdeka and @steve-gray (globalsign#110)
* cluster: fix deadlock in cluster synchronisation (globalsign#120)

For a impressively thorough breakdown of the problem, see:
	globalsign#120 (comment)

Huge thanks to @dvic and @KJTsanaktsidis for the report and fix.

* readme: credit @dvic and @KJTsanaktsidis
@aksentyev aksentyev force-pushed the support-non-string-keys-in-map branch from 73fdc99 to 19be209 Compare April 5, 2018 20:13
@aksentyev aksentyev changed the title Support non string keys in maps Support decimal type keys in maps Apr 5, 2018
@aksentyev aksentyev changed the title Support decimal type keys in maps Support decimal number type keys in maps Apr 5, 2018
@domodwyer
Copy link

Hi @aksentyev

I was under the impression that integer keys were not supported by BSON as they conflict with the internal representation of arrays in the spec. Does MongoDB support integer keys in maps?

Dom

@aksentyev
Copy link
Author

Hi @domodwyer!

No, MongoDB does not support non string keys because it stores document in bson format. But I believe that encoder/decoder packages should be able to work with all standard types (at least numeric types in map keys) and should be able to represent types if it needed.

encoding/json serializes int keys to string and vice versa (https://play.golang.org/p/DtPJ6TwB9sA)

I know that also some composite types (like structs) can be used as map keys in some cases, but if struct had a slice field it is evidently impossible (https://play.golang.org/p/vg6Vxi90CDg) to use is a map key. Strings and numeric types in map keys really covers 99% of use cases.

@domodwyer
Copy link

Hi @aksentyev

I think I'm convinced! Would you mind rebasing or pulling development into your branch to clean up the diff and we'll review, thanks!

Dom

# Conflicts:
#	.gitignore
#	README.md
#	socket.go
@aksentyev
Copy link
Author

all done!

@domodwyer domodwyer merged commit 32b18f7 into globalsign:development Apr 12, 2018
@domodwyer
Copy link

Thanks for the great PR @aksentyev!

Dom

@domodwyer domodwyer mentioned this pull request Apr 23, 2018
libi pushed a commit to libi/mgo that referenced this pull request Dec 1, 2022
* socket: only send client metadata once per socket (globalsign#105)

Periodic cluster synchronisation calls isMaster() which currently resends the
"client" metadata every call - the spec specifies:

	isMaster commands issued after the initial connection handshake MUST NOT
	contain handshake arguments

	https://github.com/mongodb/specifications/blob/master/source/mongodb-handshake/handshake.rst#connection-handshake

This hotfix prevents subsequent isMaster calls from sending the client metadata
again - fixes globalsign#101 and fixes globalsign#103.

Thanks to @changwoo-nam @qhenkart @canthefason @jyoon17 for spotting the initial
issue, opening tickets, and having the problem debugged with a PoC fix before I
even woke up.

* Merge Development (globalsign#111)

* Brings in a patch on having flusher not suppress errors. (globalsign#81)

go-mgo#360

* Fallback to JSON tags when BSON tag isn't present (globalsign#91)

* Fallback to JSON tags when BSON tag isn't present


Cleanup.

* Add test to demonstrate tagging fallback.

- Test coverage for tagging test.

* socket: only send client metadata once per socket

Periodic cluster synchronisation calls isMaster() which currently resends the
"client" metadata every call - the spec specifies:

	isMaster commands issued after the initial connection handshake MUST NOT
	contain handshake arguments

	https://github.com/mongodb/specifications/blob/master/source/mongodb-handshake/handshake.rst#connection-handshake

This hotfix prevents subsequent isMaster calls from sending the client metadata
again - fixes globalsign#101 and fixes globalsign#103.

Thanks to @changwoo-nam @qhenkart @canthefason @jyoon17 for spotting the initial
issue, opening tickets, and having the problem debugged with a PoC fix before I
even woke up.

* Cluster abended test 254 (globalsign#100)

* Add a test that mongo Server gets their abended reset as necessary.

See https://github.com/go-mgo/mgo/issues/254 and
https://github.com/go-mgo/mgo/pull/255/files

* Include the patch from Issue 255.

This brings in a test which fails without the patch, and passes with the
patch. Still to be tested, manual tcpkill of a socket.

* changeStream support (globalsign#97)

Add $changeStream support

* readme: credit @peterdeka and @steve-gray (globalsign#110)

* Hotfix globalsign#120  (globalsign#136)

* cluster: fix deadlock in cluster synchronisation (globalsign#120)

For a impressively thorough breakdown of the problem, see:
	globalsign#120 (comment)

Huge thanks to @dvic and @KJTsanaktsidis for the report and fix.

* readme: credit @dvic and @KJTsanaktsidis

* added support for marshalling/unmarshalling maps with non-string keys

* refactor method receiver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants