[ 
https://issues.apache.org/jira/browse/CASSANDRA-18153?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17680348#comment-17680348
 ] 

Stefan Miklosovic commented on CASSANDRA-18153:
-----------------------------------------------

[~abonacin] I have added a reproducer here.

When I run the test, it will print this:

{code}
/tmp/dtests4687378434417513292/node1/data0/system/local-7ad54392bcdd35a684174e047860b377/nb-2-big
 -> 00000000-0000-4000-8000-000000000001
/tmp/dtests4687378434417513292/node1/data0/system/local-7ad54392bcdd35a684174e047860b377/nb-1-big
 -> null
local host id -> 00000000-0000-4000-8000-000000000001
{code}

So you see that for the first SSTable of system.local, it will still print 
null, only the second table is correctly set on originating id so your fix is 
actually not fixing it?

If we do this:

{code}
    public MetadataCollector(ClusteringComparator comparator)
    {
        this(comparator, 
Optional.ofNullable(StorageService.instance.getLocalHostUUID()).orElseGet(SystemKeyspace::getLocalHostId));
    }
{code}

if StorageService.instance.getLocalHostUUID() is null, it will call 
SystemKeyspace::getLocalHostId, but the problem is that the implementation of 
that method reads data on disk:

{code}
    /**
     * Read the host ID from the system keyspace.
     */
    public static UUID getLocalHostId()
    {
        String req = "SELECT host_id FROM system.%s WHERE key='%s'";
        UntypedResultSet result = executeInternal(format(req, LOCAL, LOCAL));

        // Look up the Host UUID (return it if found)
        if (result != null && !result.isEmpty() && result.one().has("host_id"))
            return result.one().getUUID("host_id");

        return null;
    }
{code}

But here it returns null and the reason for that is that when the very first 
SSTable for system.local is going to be written, there is no SSTable in 
system.local yet, so it has nowhere to read that id from.

The solution to this would be to cache host id so if "getLocalHostId" returns 
null, we would set it via "setLocalHostId" or similar (I am just shooting the 
ideas here ... might be done differently).

I was trying to use "SystemKeyspace.getOrInitializeLocalHostId" but the test 
was stuck as I think it was in the loop because it was reading non-existing / 
empty table yet and then it tried to persist generated uuid ....

(1) 
https://github.com/instaclustr/cassandra/commit/1b17b5191e303b76d9d2888c08934e2520c46291

> Memtable being flushed without hostId in version "me" and newer during 
> CommitLogReplay
> --------------------------------------------------------------------------------------
>
>                 Key: CASSANDRA-18153
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-18153
>             Project: Cassandra
>          Issue Type: Bug
>          Components: Local/SSTable
>            Reporter: Adriano Bonacin
>            Assignee: Adriano Bonacin
>            Priority: Normal
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> On ticket CASSANDRA-16619 some files were changed to allow Cassandra to store 
> HostID in the new "me" SSTable version.
> But SSTables flushed during CommitLogReplay miss this HostID info.
>  
> In the next Cassandra startup, if these SSTables were still present, 
> system.log will show:
> {{WARN Origin of 3 sstables is unknown or doesn't match the local node; 
> commitLogIntervals for them were ignored}}
> {{WARN }}{{{}Origin of 3 sstables is unknown or doesn't match the local node; 
> commitLogIntervals for them were ignored{}}}{{{}{}}}{{ }}
>  
> And debug.log will show a list of SSTables, witch can include "md" and "me" 
> version (before upgradesstables):
>  
> {{Ignored commitLogIntervals from the following sstables: 
> [/var/lib/cassandra/data/system/compaction_history-b4dbb7b4dc493fb5b3bfce6e434832ca/me-3-big-Data.db,
>  
> /var/lib/cassandra/data/system/compaction_history-b4dbb7b4dc493fb5b3bfce6e434832ca/md-1-big-Data.db,
>  
> /var/lib/cassandra/data/system/compaction_history-b4dbb7b4dc493fb5b3bfce6e434832ca/md-2-big-Data.db]}}
>  
> https://issues.apache.org/jira/browse/CASSANDRA-16619



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to