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

session.getDataHashCode not equals Arrays.hashCode( attributesData ) when session attributes whithout changes by msm-kryo-serializer #334

Open
51037405 opened this issue Jan 20, 2017 · 5 comments

Comments

@51037405
Copy link

final ConcurrentMap<String, Object> attributes = _session.getAttributesFiltered();
            final byte[] attributesData = serializeAttributes( _session, attributes );
            final int hashCode = Arrays.hashCode( attributesData );
            //<editor-fold desc="additional logs">
            if ( _log.isDebugEnabled() ) {
                _log.debug( "attributesData  " + new String(attributesData) );
                _log.debug( "Arrays.hashCode " + hashCode + ",Session.getDataHashCode " + _session.getDataHashCode() );
            }
            final BackupResult result;
            //</editor-fold>
            if ( _session.getDataHashCode() != hashCode
                    || _force
                    || _session.authenticationChanged() ) {

                _session.setLastBackupTime( System.currentTimeMillis() );
                final byte[] data = _transcoderService.serialize( _session, attributesData );

                result = doBackupSession( _session, data, attributesData );
                if ( result.isSuccess() ) {
                    _session.setDataHashCode( hashCode );
                }
            } else {
                result = new BackupResult( BackupResultStatus.SKIPPED );
            }

session will be backup when _session.getDataHashCode != Arrays.hashCode( attributesData ) ,sometiems, session attributes without any changes, but attributesData has changed .
For example:
put two attributes into session, (iccid = 1234 , cityCode = heibei )
first access log:

Jan 19, 2017 4:11:53 PM de.javakaffee.web.msm.BackupSessionTask call FINE: attributesData  cityCod�heibe�icci�123� 
Jan 19, 2017 4:11:53 PM de.javakaffee.web.msm.BackupSessionTask call FINE: Arrays.hashCode -1759883946,Session.getDataHashCode 1744582514 Jan 19, 2017 4:11:53 PM 

second access log

Jan 19, 2017 4:11:55 PM de.javakaffee.web.msm.BackupSessionTask call FINE: attributesData icci�123�cityCod�heibe� 
Jan 19, 2017 4:11:55 PM de.javakaffee.web.msm.BackupSessionTask call FINE: Arrays.hashCode 1744582514,Session.getDataHashCode -1759883946 Jan 19, 2017 4:11:55 PM 

in this case, session will be covered in concurrent requests even if the attributes have not changes.
image

If Req_A is a get request, just read session attributes ,Req_B is a post request ,modify session attributes .
Session will be covered when Req_A finished.
So, i will get the attribute from session that is set by Req_B is null in the next request.
How to solve this question?

@51037405
Copy link
Author

version info:
msm : 2.1.1
kryo : 4.0.0
kryo-serializers : 0.41
minlog : 1.2
objenesis: 2.2
reflectasm: 1.11.3
asm: 5.0.4
setting:

<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"  
		memcachedNodes="n1:172.16.50.65:11211"            
		requestUriIgnorePattern=".*\.(png|gif|jpg|css|js)$"  
		sticky="false"
		sessionBackupAsync="false"
		sessionBackupTimeout="1800000"  
		copyCollectionsForSerialization="false"  
		transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"/>

@magro
Copy link
Owner

magro commented Jan 28, 2017

Thanks for this detailed report! AFAICS the two request logs show a different order of the attributes (attributesData), which most probably explains the different hashcode. Therefore we'd have to sort attributes before computing the hashcode. WDYT?
Do you want to submit a pull request?

@51037405
Copy link
Author

51037405 commented Feb 3, 2017

Thanks for the reply!
Now we get hashcode by the attributesData(the attributes has been serialized).
If sort attributes before computing the hashcode , we'll get hashcode by the attributes has been ordered instead of the attributesData, right?
Or we sort attributes before serialize attributes?

@magro
Copy link
Owner

magro commented Feb 3, 2017

Right, I meant to sort the attributes (the result of _session.getAttributesFiltered()).

51037405 added a commit to 51037405/memcached-session-manager that referenced this issue Feb 4, 2017
51037405 added a commit to 51037405/memcached-session-manager that referenced this issue Feb 4, 2017
@51037405
Copy link
Author

51037405 commented Feb 4, 2017

Thank you very much! I got the same hashcode when the attributes been sorted.

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

No branches or pull requests

2 participants