OwlCyberSecurity - MANAGER
Edit File: caching.cpython-312.pyc
� ����U��g�$�����������������������������d�Z�ddlZddlmZmZ�ddlmZ�ddlZddlZddlm Z ��ej������������������d�������ZdZdd �Z �G�d ��de�������Z�G�d��d e�������Z�G�d��de�������Z�G�d��de�������Zy)z0Implementing caching mechanisms for MySQL Fabric�����N)�datetime� timedelta)�sha1����)�FabricShardzmyconnpy-fabric�<���c�����������������������|dk��rt��������d��������|�t��������|��������}||k��r||z���dz��}||�|���kD��r|}n|dz���}||k��r�|�j������������������||��������y)z�Similar to bisect.insort_right but for reverse sorted lists This code is similar to the Python code found in Lib/bisect.py. We simply change the comparison from 'less than' to 'greater than'. r���zlow must be non-negativeN����r���)� ValueError�len�insert)�alist�new_element�low�high�middles��� �u/opt/hc_python/lib64/python3.12/site-packages/../../../lib/python3.12/site-packages/mysql/connector/fabric/caching.py�insort_right_revr���'���sm��������Q�w��3�4�4��|��5�z�� ��*���*��"����v��&��D��1�*�C����*�� �L�L��k�"�����c��������������������L�����e�Zd�ZdZddefd�Zedd���������Zed����������Z d��Z d��Zy) � CacheEntryz)Base class for MySQL Fabric cache entriesNc������������������`�����||�_���������||�_��������t��������j��������������������������|�_��������||�_��������y��N)�version�fabric_uuidr����utcnow�last_updated�_ttl)�selfr���r����ttls��� r����__init__zCacheEntry.__init__?���s'���������&���$�O�O�-����� r���c�����������������������t����������)�Create hash for indexing)�NotImplementedError��cls�part1�part2s��� r���� hash_indexzCacheEntry.hash_indexE���s �������"�!r���c�����������������������|�j�������������������sy|�j�������������������t��������|�j��������������������������z���}t��������j��������������������������|kD��S�)z�Returns True if entry is not valid any longer This property returns True when the entry is not valid any longer. The entry is valid when now > (last updated + ttl), where ttl is in seconds. F)�seconds)r���r���r���r���r���)r����atimes��� r����invalidzCacheEntry.invalidJ���s;�������� � ���!�!�I�d�i�i�$@�@����� �5�(�(r���c������������������6�����t��������j��������������������������|�_��������y)zReset the Time to LiveN)r���r���r����r���s��� r���� reset_ttlzCacheEntry.reset_ttlW���s������$�O�O�-��r���c�����������������������d|�_���������y)zInvalidates the cache entryN)r���r/���s��� r���� invalidatezCacheEntry.invalidate[���s ������ ��r���r���)�__name__� __module__�__qualname__�__doc__� _CACHE_TTLr!����classmethodr)����propertyr-���r0���r2�����r���r���r���r���;���sC������3�#��:�����"���"��� )��� )�.�!r���r���c��������������������H�������e�Zd�ZdZd��fd� Zd��Zd��Zedd���������Zd��Z ��xZ S�) �CacheShardTablez&Cache entry for a Fabric sharded tablec�����������������������t��������|t���������������st��������d��������t��������t��������|����||���������i�|�_��������||�_��������g�|�_��������g�|�_ ��������|j������������������r4|j������������������r'|�j������������������|j������������������|j��������������������������y�y�y�)Nz-shard argument must be a FabricShard instance�r���r���) � isinstancer���r����superr<���r!����partitioning�_shard�keys� keys_reversed�key�group� add_partition)r����shardr���r���� __class__s��� �r���r!���zCacheShardTable.__init__d���s}��������%��-��L�M�M� �o�t�-�g�:E�� .�� G��������� �����9�9�������u�y�y�%�+�+�6��%�9r���c������������������.�����t��������|�j������������������|�������S�r���)�getattrrB���)r����attrs��� r����__getattr__zCacheShardTable.__getattr__q���s�������t�{�{�D�)�)r���c������������������N����|�j�������������������dk(��rt��������|�������}n�|�j�������������������dk(��rA �d|v�rt��������j������������������|d�������}n$t��������j������������������|d�������j ��������������������������}nD|�j�������������������dk(��rn4|�j�������������������dk(��rn$t��������d j ������������������|�j����������������������������������d |i|�j������������������|<���|�j���������������������������t��������j������������������|�j������������������|��������t��������|�j������������������|��������y#��t��������dj ������������������|���������������xY�w)z$Add sharding information for a group�RANGE�RANGE_DATETIME�:z%Y-%m-%d %H:%M:%Sz%Y-%m-%dz0RANGE_DATETIME key could not be parsed, was: {0}�RANGE_STRING�HASHzUnsupported sharding type {0}rF���N)� shard_type�intr����strptime�dater����formatrA���r0����bisect�insort_rightrC���r���rD���)r���rE���rF���s��� r���rG���zCacheShardTable.add_partitiont���s������?�?�g�%��c�(�C� �_�_� 0� 0� ��#�:�"�+�+�C�1D�E�C�"�+�+�C��<�A�A�C�C����_�_�� .�� �_�_�� &���<�C�C�������� �� �U�" ����#��� �������D�I�I�s�+���+�+�S�1��% � �F�M�M������s����?D��D$c������������������v�����t��������|j������������������d�������|j������������������d�������z����������j��������������������������S��r#���zutf-8�r����encode� hexdigestr%���s��� r���r)���zCacheShardTable.hash_index����s/��������E�L�L��)�E�L�L��,A�A�B�L�L�N�Nr���c������������������|�����dj������������������|�j������������������|�j������������������|�j������������������|�j��������������������������S�)Nz%{class_}({database}.{table}.{column}))�class_�database�table�column)rX���rI���rb���rc���rd���r/���s��� r����__repr__zCacheShardTable.__repr__����s6������6�=�=��>�>��]�]��*�*��;�;� �>�� �� r����NNr���)r3���r4���r5���r6���r!���rM���rG���r8���r)���re���� __classcell__�rI���s���@r���r<���r<���`���s0�������0�7�*�2�<��O���O� r���r<���c��������������������:�������e�Zd�ZdZ��fd�Zedd���������Zd��Z��xZS�)� CacheGroupzCache entry for a Fabric groupc������������������L������t���������t��������|����d�d����������||�_��������||�_��������y�)Nr>���)r@���rj���r!���� group_name�servers)r���rl���rm���rI���s��� �r���r!���zCacheGroup.__init__����s%������� �j�$�(��4�(�H�$�����r���c������������������R�����t��������|j������������������d��������������j��������������������������S�r\���r]���r%���s��� r���r)���zCacheGroup.hash_index����s!��������E�L�L��)�*�4�4�6�6r���c������������������P�����dj������������������|�j������������������|�j��������������������������S�)Nz{class_}({group}))ra���rF���)rX���rI���rl���r/���s��� r���re���zCacheGroup.__repr__����s(������"�)�)��>�>��/�/��*�� �� r���r���) r3���r4���r5���r6���r!���r8���r)���re���rg���rh���s���@r���rj���rj�������s$�������(�� ��7���7� r���rj���c��������������������F�����e�Zd�ZdZefd�Zd��Zd��Zdd�Zd��Z d��Z d ��Zd ��Zy)�FabricCachezfSingleton class for caching Fabric data Only one instance of this class can exists globally. c�����������������������||�_���������i�|�_��������i�|�_��������t��������j��������������������������|�_��������t��������j��������������������������|�_��������y�r���)r���� _sharding�_groups� threading�Lock�_FabricCache__sharding_lock�_FabricCache__groups_lock)r���r ���s��� r���r!���zFabricCache.__init__����s5�������� �������(�~�~�/���&�^�^�-��r���c�����������������������|�j�������������������5�� �|�j������������������|=�t��������j������������������d��������ddd��������y#�t��������$�r�Y��w�xY�w#�1�sw�Y���yxY�w)zRemove cache entry for groupzGroup removed from cacheN)rx���rt����_LOGGER�debug�KeyError�r���� entry_hashs��� r����remove_groupzFabricCache.remove_group����sP������ � � � :��L�L��,� �� � �8�9�� � ����� �� ��� � �s+����A � :�A � A�A �A�A � Ac�����������������������|�j�������������������5�� �|�j������������������|=�ddd��������y#�t��������$�r�Y��w�xY�w#�1�sw�Y���yxY�w)zRemove cache entry for shardN)rw���rs���r|���r}���s��� r����remove_shardtablezFabricCache.remove_shardtable����sA������ � !� !� ��N�N�:�.��"� !����� �� ���"� !�s����4� %� 1�4�1�4�=Nc������������������^����t���������j������������������|j������������������|j�������������������������}|�j������������������5�� �|�j ������������������|���}|j ������������������|j������������������|j��������������������������ddd��������y#�t��������$�r �t��������|||��������}||�j ������������������|<���Y��1w�xY�w#�1�sw�Y���yxY�w)zCache information about a shardr>���N) r<���r)���rb���rc���rw���rs���rG���rE���rF���r|���)r���rH���r���r���r~����entrys��� r����sharding_cache_tablez FabricCache.sharding_cache_table����s�������$�/�/�������L� � � !� !� 3����z�2���#�#�E�I�I�u�{�{�;��"� !����� 3�'��w�4?�A��-2����z�*� 3�� �"� !�s(����B#�5A7�7&B �B#�B � B#�#B,c����������������������t���������j������������������|�������}|�j������������������5�� �|�j������������������|���}||_��������|j���������������������������t��������j������������������dj������������������||���������������ddd��������y#�t��������$�rC�t��������||�������}||�j������������������|<���t��������j������������������dj������������������||���������������Y��Tw�xY�w#�1�sw�Y���yxY�w)zCache information about a groupzRecaching group {0} with {1}zCaching group {0} with {1}N) rj���r)���rx���rt���rm���r0���rz���r{���rX���r|���)r���rl���rm���r~���r����s��� r����cache_groupzFabricCache.cache_group����s��������*�*�:�6� � � � � *����Z�0�� '�� ����!�� � �<�C�C���)��*�� � ����� *�"�:�w�7��+0����Z�(�� � �:�A�A���)��*� *��� � �s*����C�AA8�8A C�C�C�C�Cc�����������������������t���������j������������������||�������}d} �|�j������������������|���}|j������������������r6t��������j������������������dj ������������������|���������������|�j������������������|��������y �|S�#�t��������$�r�Y�yw�xY�w)z4Search cache for a shard based on database and tableN�{0} invalidated) r<���r)���rs���r-���rz���r{���rX���r����r|���)r���rb���rc���r~���r����s��� r����sharding_searchzFabricCache.sharding_search����s|������$�/�/��%�@� ��� ��N�N�:�.�E��}�}�� � �/�6�6�u�=�>��&�&�z�2�������� ��� �� �s����AA.��. A:�9A:c�����������������������t���������j������������������|�������}d} �|�j������������������|���}|j������������������r6t��������j������������������dj ������������������|���������������|�j������������������|��������y �|S�#�t��������$�r�Y�yw�xY�w)z*Search cache for a group based on its nameNr����) rj���r)���rt���r-���rz���r{���rX���r���r|���)r���rl���r~���r����s��� r����group_searchzFabricCache.group_search��sz�������*�*�:�6� ��� ��L�L��,�E��}�}�� � �/�6�6�u�=�>��!�!�*�-�������� ��� �� �s����AA-��- A9�8A9c�����������������������dj������������������|�j������������������t��������|�j�������������������������t��������|�j���������������������������������S�)Nz-{class_}(groups={nrgroups},shards={nrshards}))ra����nrgroups�nrshards)rX���rI���r���rt���rs���r/���s��� r���re���zFabricCache.__repr__��s:������>�E�E��>�>�����&�����(��F�� �� r���rf���) r3���r4���r5���r6���r7���r!���r���r����r����r����r����r����re���r:���r���r���rq���rq�������s4��������&��.� :��3�*�$�"�" r���rq���)r���N)r6���rY���r���r����hashlibr����loggingru�����r���� getLoggerrz���r7���r����objectr���r<���rj���rq���r:���r���r����<module>r�������so�����0�7����(��������� �'� � �-� .�� � �#�("!���"!�J= �j��= �@ ��� �$g �&��g r���