You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: cross_cluster_task.go
    path of file: ./repos/cadence/service/history/task
    
    the code of the file until where you have to start completion: // Copyright (c) 2021 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. I
    
func (t *crossClusterSourceTask) isValidLocked() bool {
	if t.processingState == processingStateInvalidated {
		return false
	}

	domainCache := t.shard.GetDomainCache()
	sourceEntry, err := domainCache.GetDomainByID(t.GetDomainID())
	if err != nil {
		// unable to tell, treat the task as valid
		t.logger.Error("Failed to load domain entry", tag.Error(err))
		return true
	}

	var targetEntry *cache.DomainCacheEntry
	// for apply parent policy, target workflow infomation is not
	// persisted with the task, so skip this test for target workflow since the check is best effort
	// TODO: we should check the TargetDomainIDs field
	if t.GetTaskType() != persistence.CrossClusterTaskTypeApplyParentClosePolicy {
		targetEntry, err = domainCache.GetDomainByID(t.Info.(*persistence.CrossClusterTaskInfo).TargetDomainID)
		if err != nil {
			return true
		}
	}

	// pending active state is treated as valid
	sourceInvalid := sourceEntry.GetReplicationConfig().ActiveClusterName !=
		t.shard.GetClusterMetadata().GetCurrentClusterName()
	targetInvalid := targetEntry != nil && targetEntry.GetReplicationConfig().ActiveClusterName != t.targetCluster

	if sourceInvalid || targetInvalid {
		t.processingState = processingStateInvalidated
		return false
	}

	return true
}